0

有人可以帮助下面的代码。我正在尝试创建一个注册查询,但是当它被提交时,我收到以下行的错误:

$insert_query = "insert into members (First_name, last_name, Address_1, Address_2, Postcode, Email, Membership_Number, Password) values('$fname','$lname','$address1','$address2','$postcode','$email','$member','$password')";

这仅影响 first_name,因为其他字段名称已成功提交。

您的帮助将不胜感激!!

    <?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
$select_db = mysql_select_db("thistlehc",$con);
if(isset($_POST['register']))

 $fname = mysql_real_escape_string($_POST['fname']);
 $lname = mysql_real_escape_string($_POST['lname']);
 $address1 = mysql_real_escape_string($_POST['address1']);
 $address2 = mysql_real_escape_string($_POST['address2']);
 $postcode = mysql_real_escape_string($_POST['postcode']);
 $email = mysql_real_escape_string($_POST['email']);
 $member = mysql_real_escape_string($_POST['member']);
 $password = mysql_real_escape_string($_POST['password']);

 $query = "select membership_number from members where membership_number='$member'";
 $link = mysql_query($query)or die(mysql_error());
     $num = mysql_num_rows($link);

     if ($num>0){
      echo 'Membership Number already exists'; //Membership number already taken
     }

     else {
     $insert_query = "insert into members (First_name, last_name, Address_1, Address_2, Postcode, Email, Membership_Number, Password) values('$fname','$lname','$address1','$address2','$postcode','$email','$member','$password')";
     $result = mysql_query($insert_query)or die(mysql_error());
     echo "Registered Successfully!";
     }

?>
4

1 回答 1

2

在我看来,就像您忘记封装您的if声明的内容一样。

if(isset($_POST['register']))

因为它在要执行的代码周围没有大括号,所以只执行紧随其后的第一行。在您的情况下,该语句似乎返回 false,并且未执行if行定义,因此是未定义的变量。$fname

你想使用类似的东西 -

if(isset($_POST['register'])){
 $fname = mysql_real_escape_string($_POST['fname']);
 $lname = mysql_real_escape_string($_POST['lname']);
 $address1 = mysql_real_escape_string($_POST['address1']);
 ...
}
于 2013-01-05T22:55:58.607 回答