Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,634
    Thanks
    0
    Thanked 649 Times in 639 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.

    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •