开发者

PHP wont update/insert

开发者 https://www.devze.com 2023-03-29 07:15 出处:网络
So here is my code, have no ide why its not working have been looking at it for hours, points to anyone who can figure it out. The variables are passed 开发者_Python百科fine, and server connection mad

So here is my code, have no ide why its not working have been looking at it for hours, points to anyone who can figure it out. The variables are passed 开发者_Python百科fine, and server connection made. The error message the browser gives is,

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'username'', 'Saturday 20th of August 2011 02:02:22 PM', 'first', 'last', 'ssn' at line 2

i replaced the variable data back with the variable name so you can get an idea, so where is says first, the browser actually shows the first name i entered.

Thanks!

$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();


Username is probably username'. Try to add mysql_real_escape_string() around your variables and read about SQL Injection

0

精彩评论

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