Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 08:38 AM   PM User | #1
anthonyw17
New to the CF scene

 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
anthonyw17 is an unknown quantity at this point
Angry 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

PHP Code:
<?php
session_start
();

$con mysql_connect("localhost","MyUser","MySecretPass");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("membersys"$con);

$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'");

Header("Location: acc_content.php?account=updated");

mysql_close($con);
?>
Any Ideas?
anthonyw17 is offline   Reply With Quote
Old 01-19-2013, 09:07 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.

Code:
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:53 AM.


Advertisement
Log in to turn off these ads.