Update form with variables ID?

Discussion in 'PHP' started by jmansa, Dec 11, 2005.

  1. #1
    I have a update form where I get variable data by typing : www.mysite.com/form.php?userid=1

    That part is pretty easy, but when i want to process the data through a update page, something goes wrong. Can't see the problem so if anybody can, please help...

    FORM:
    
    <?php
    if (($_GET['uid']) && (is_numeric($_GET['uid']))) {
    $userid = $_GET['uid'];
    
    $dbhost = 'localhost';
    $dbuser = 'username';
    $dbpass = 'password';
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die 
    ('Error connecting to mysql');
    
    $dbname = 'database';
    mysql_select_db($dbname);
    
    $query="SELECT * FROM tabel WHERE id=$userid";
    $result=mysql_query($query) or die("Unable to find requested user");
    $currUser = mysql_fetch_array($result);
    ?>
    <form name="form1" method="post" action="update.php">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><input name="ID" type="hidden" id="ID" value="<? $_GET['uid'] ?>">
          <input name="Name" type="text" id="Name" value="<? echo ("" . 
    $currUser['Name'] . ""); ?>"></td>
        </tr>
        <tr>
          <td><input name="Email" type="text" id="Email" value="<? echo ("" . 
    $currUser['Email'] . ""); ?>"></td>
        </tr>
        <tr>
          <td><input name="Homepage" type="text" id="Homepage" value="<? 
    echo ("" . $currUser['Homepage'] . ""); ?>"></td>
        </tr>
        <tr>
          <td><input type="submit" name="Submit" value="Update"></td>
        </tr>
      </table>
    </form>
    <?
    } else {
    echo "No user specified";
    }
    ?>
    
    Code (markup):
    ...and my update page:

    
    <?php
    $ID=$_POST['ID'];
    $Name=$_POST['Name'];
    $Email=$_POST['Email'];
    $Homepage=$_POST['Homepage'];
    
    $dbhost = 'localhost';
    $dbuser = 'username';
    $dbpass = 'password';
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting 
    to mysql');
    
    $dbname = 'database';
    mysql_select_db($dbname);
    
    $query = "UPDATE tabel SET Name = '$Name', Email = '$Email', Homepage = 
    '$Homepage' WHERE ID='$userid'";
    
    mysql_query($query);
    echo "<a href=\"\form.php?uid='$userid'\">Updated - Back</a>";
    mysql_close();
    ?>
    
    Code (markup):
    PLEASE HELP...
     
    jmansa, Dec 11, 2005 IP
  2. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #2
    replace
    
     <td><input name="ID" type="hidden" id="ID" value="<? $_GET['uid'] ?>">
    
    Code (markup):
    with
    
     <td><input name="ID" type="hidden" id="ID" value="<? echo $userid?>">
    
    Code (markup):
    See if that helps
     
    Big 'G', Dec 12, 2005 IP
  3. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #3
    Yeah it looks like your script is passing the variables as POST variables instead of GET, change all of the $_GET to $_POST and that SHOULD work, I am lazy and just use $_REQUEST. This will require your register_globals to be set to 'on' IIRC.
     
    palespyder, Dec 12, 2005 IP