PHP不会更新/插入

时间:2011-08-20 21:11:03

标签: php

所以这是我的代码,不知道为什么它不工作已经看了几个小时,指向任何能够解决它的人。变量传递正常,并建立服务器连接。浏览器提供的错误消息是

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在“用户名”附近使用正确的语法,'2011年8月20日星期六02:02:22','第一','最后','ssn'在第2行

我用变量名替换了变量数据,这样你就可以得到一个想法,所以首先说的是,浏览器实际上显示了我输入的名字。

谢谢!

$HTTP_COOKIE_VARS['username'] = $username;
$email = $_REQUEST['email'];
 $Todaysdate = date('l jS \of F Y h:i:s A');
 $firstname = $_REQUEST['firstname'];
 $lastname = $_REQUEST['lastname'];
 $ssn = $_REQUEST['ssn'];  
 $street = $_REQUEST['street']; 
 $city = $_REQUEST['city'];
 $zip = $_REQUEST['zip'];
 $phone1 = $_REQUEST['phone1'];
 $phone2 = $_REQUEST['phone2']; 
 $hdhas = $_REQUEST['hdhas'];
 $mi= $_REQUEST['mi'];





 $query = ("INSERT INTO Members (username, email, todaysdate, firstname, lastname, ssn,       street, city, zip, phone1, phone2, hdhas, mi)
 VALUES('$username','$email', '$Todaysdate', '$firstname', '$lastname', '$ssn', '$street', '$city', '$zip', '$phone1', '$phone2', '$hdhas', '$mi')");



 $checkuser = mysql_query("SELECT username FROM Members WHERE username='$username'"); 


 if(mysql_num_rows($checkuser)>0)
{
 mysql_query("UPDATE Members SET email='$email', username='$username', todaysdate='$Todaysdate', firstname='$firstname', lastname='$lastname', ssn='$ssn',  street='$street', city='$city', zip='$zip', phone1='$phone1', phone2='$phone2',  hdhas='$hdhas', mi='$mi' WHERE username = '$username'");
 } 

else {
mysql_query($query);
}

mysql_query($query) or die(mysql_error());
mysql_close();

1 个答案:

答案 0 :(得分:4)

用户名可能是username'。尝试在变量周围添加mysql_real_escape_string()并阅读SQL Injection