我目前正在处理我网站的登录/注册页面,但我遇到的问题是 PHP 脚本没有将行添加到数据库中。几天来我一直试图解决这个问题,但我还没有想出解决方案。提交时页面上也没有错误...
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
if(isset($_POST['f_name']) && !empty($_POST['f_name']) &&
isset($_POST['l_name']) && !empty($_POST['l_name']) &&
isset($_POST['reg_email']) && !empty($_POST['reg_email']) &&
isset($_POST['conf_email']) && !empty($_POST['conf_email']) &&
isset($_POST['password']) && !empty($_POST['password']) &&
$_POST['birthday-day'] != 0 &&
$_POST['birthday-month'] != 0 &&
$_POST['birthday-year'] != 0)
{
$f_name = mysql_real_escape_string($_POST['f_name']);
$l_name = mysql_real_escape_string($_POST['l_name']);
$reg_email = mysql_real_escape_string($_POST['reg_email']);
$conf_email = mysql_real_escape_string($_POST['conf_email']);
$password = mysql_real_escape_string($_POST['password']);
$b_day = $_POST['birthday-day'];
$b_month = $_POST['birthday-month'];
$b_year = $_POST['birthday-year'];
$search = mysql_query("SELECT email FROM users WHERE email='".$reg_email."'");
$match = mysql_num_rows($search);
if($reg_email !== $conf_email) {
$msg = "The emails dont match.";
}
if (!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $reg_email)) {
$msg = "The email you have entered is invalid. Please try again.";
}
if ($match > 0) {
$msg = "Email address already registered. Please enter a different one.";
} else {
mysql_query("INSERT INTO userstest (f_name, l_name, email, password) VALUES(
'".$f_name."',
'".$l_name."',
'".$reg_email."',
'".$password."') ") or die(mysql_error());
}
}
else {
//code
}
形式...
<form name="register" action="<?php print ($_SERVER['PHP_SELF']); ?>" method="post" class="regform" >
<input type="text" name="f_name" class="f_name" placeholder="First Name" />
<input type="text" name="l_name" class="l_name" placeholder="Last Name" />
<input type="text" name="reg_email" class="reg_email" placeholder="Email" />
<input type="text" name"conf_email" class="conf_email" placeholder="Re-enter Email" />
<input type="password" name="password" class="reg_pass" placeholder="Password" />
<div id="birthday">
<h1>
BIRTHDAY
</h1>
<select name="birthday-day" id="day" class="day">
<option value="0">Day</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
...etc
</select>
<select name="birthday-month" class="month">
<option value="0">Month</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
</select>
<select name="birthday-year" class="year">
<option value="0">Year</option>
<option value="1994">1994</option>
</select>
</div>
<div id="submitbutton">
<input type="submit" name="submit" class="reg_submit" value="REGISTER" />
</div>
</form>
这可能是一个我没有看到的简单语法错误,但我感谢我得到的任何帮助。