Problem with form and MySql update

Discussion in 'PHP' started by gilgil2, Sep 11, 2012.

  1. #1
    I think this is a pretty simple issue and I have done it before but I am just not sure what is going wrong. The database updates but not with the password, it just deletes what was there before and replaces it with nothing, so there is a problem with posting the password but I don't know what, the echo password does work.

    
    <?php
    $x = $_GET['x'];$y = $_GET['y'];
    echo $x;echo $y;
    
    echo '<form action="reset.php" method="post">Password <input type="password" name="password" /><input type="submit" value="Submit" /></form>';
    
    $password = $_POST['password'];
      $link = mysql_connect('x', 'x', 'x');          if (!$link)          {           die('Could not connect: ' . mysql_error());          }         mysql_select_db('unsignedgigs');        $query = "UPDATE users SET `password`='$password' WHERE `username`='$x'";
    $result = mysql_query($query) or die (mysql_error());
    echo $password;
    ?>
    
    PHP:
    p.s. I will encrypt escape once I get it working.

    Thanks
     
    Solved! View solution.
    gilgil2, Sep 11, 2012 IP
  2. mbaldwin

    mbaldwin Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Have you echoed your mysql_error() to see what you are getting there?

    
    die(echo mysql_error());
    
    Code (markup):
    Michael
     
    mbaldwin, Sep 11, 2012 IP
  3. #3
    It has nothing to do with the query. Form submission clears all of your $_GET variables and therefore MySQL doesn't know what to update. Either switch to $_POST completely or at least pass the given data by using additional hidden form fields.
     
    Web Solutions, Sep 12, 2012 IP
  4. gilgil2

    gilgil2 Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Thanks web solutions, that solved it.
     
    gilgil2, Sep 12, 2012 IP