开发者

using external php file in html form

I am trying to create simple user registration form. I have an index.html file and a register.php file. When I click the submit button it goes to the register.php page, but nothing happens. There's no error or anything. I have some echo statements in register.php but they also don't work.

This is the code for index.html:

<form action="register.php" method="post">
<table width="384" border="1" align="center">
<? echo '<tr><td colspan="2">'.$final_report.'</td></tr>';?>
<tr>
<td width="50%">Username:</td>
<td width="50%"><label>
  <input name="username" type="text" id="username" size="30" />
</label></td>
</tr>
<tr>
  <td>Password:</td>
  <td><input name="password" type="password" id="password" value="" size="30" /></td>
</tr>
<tr>
  <td>Email:</td>
  <td><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td><label>
    <input name="register" type="submit" id="register" value="Register" />
  </label></td>
</tr>
  </table>
  </form>    

This is code for register.php:

<? 
include_once"config.php";
if(isset($_POST['register'])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$memip = $_SERVER['REMOTE_ADDR'];
$date = date("d-m-Y");
if($username == NULL OR $password == NULL OR $email == NULL){
$final_report.= "Please complete the form below..";
}else{
if(strlen($username) <= 3 || strlen($username) >= 30){
$final_report.="Your username must be between 3 and 30 characters..";
}else{
$check_members = mysql_query开发者_运维百科("SELECT * FROM `members` WHERE `username` =    '$username'");   
if(mysql_num_rows($check_members) != 0){
$final_report.="The username is already in use!";  
}else{ 
if(strlen($password) <= 6 || strlen($password) >= 12){
$final_report.="Your password must be between 6 and 12 digits and characters..";
}else{
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",         $email)){ 
$final_report.="Your email address was not valid..";
}else{
$create_member = mysql_query("INSERT INTO `members` (`id`,`username`, `password`,`email`, `ip`, `date`) 
VALUES('','$username','$password','$email','$memip','$date')"); 
$final_report.="Thank you for registering, you may login."; 
}}}}}}
?>

Can anyone see the error?


include_once"config.php"

You seem to be missing a space. Either make it include_once "config.php" (notice the space in between) or include_once("config.php").

Also you set $final_report in register.php but I don't see where you are actually printing anything.

Edit: I see you are trying to print $final_report in index.php. This won't work as you expect unless you include the register.php code directly into index.html. Why don't you just have a single register.php file with both the registration script and the HTML code?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜