Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Updating rows in a mysql table
01-19-2013, 08:38 AM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
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, 09:07 AM #2
- Join Date
- Sep 2005
- Sydney, Australia
- Thanked 624 Times in 614 Posts
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'")
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.