||01-19-2013 09:38 AM
Updating rows in a mysql table
Hey I im trying to udpate the rows PassWord, email, Age in my membersys table of my mysql database. With the code im using its only saving the age and nothing else.
Also the the new info is coming from a form using the POST method
$con = mysql_connect("localhost","MyUser","MySecretPass");
die('Could not connect: ' . mysql_error());
$ui = $_POST['username'];
$pi = $_POST['password'];
$ei = $_POST['email'];
$ag = $_POST['age'];
$user = $_SESSION['UserName'];
mysql_query("UPDATE Member SET PassWord=$ui WHERE UserName='$user'");
mysql_query("UPDATE Member SET email=$ei WHERE UserName='$user'");
mysql_query("UPDATE Member SET Age=$ag WHERE UserName='$user'");
||01-19-2013 10:07 AM
Is there some particular reason why you are trying to use three queries to do the job of one?
Also since the password and email are text fields and not numbers the values need to be wrapped in quotes.
mysql_query("UPDATE Member SET PassWord='$ui', email='$ei', Age=$ag WHERE UserName='$user'")
Note also that the mysql_ interface is obsolete and marked for deletion from PHP - Use the mysqli_ interface instead.
Also use prepare and bind instead of query so as to keep the data separate from the query.
Finally never assign $_POST values directly to fields - you should validate their content first.
|All times are GMT +1. The time now is 07:35 PM.
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.