PHP MySQL UPDATE

Discussion in 'Software' started by patriic48@gmail.com, Dec 5, 2012.

  1. patriic48@gmail.com

    patriic48@gmail.com

    Joined:
    Oct 13, 2012
    Messages:
    9
    Location:
    Middle Sweden
    Can anyone help me with correcting this page so it works?

    Seems to have a problem with this line esp, $id=($_GET["id"]);

    <?php
    echo '<html>
    <head>
    <title>Edit a Record from MySQL Database</title>
    </head>
    <body>
    <form method="post" action="update_ac.php">';

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

    mysql_select_db("my_db", $con);

    // get value of id that sent from address bar
    $id=($_GET["id"]);


    // Retrieve data from database
    $sql="SELECT * FROM persons WHERE id='$id'";

    $result=mysql_query($sql);

    echo "<table border='1'>
    <tr>
    <th>ID</th>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
    </tr>";

    while ($row = mysql_fetch_array($result)){
    $id = $row['id'];
    $FirstName = $row['FirstName'];
    $LastName = $row['LastName'];
    $Age = $row['Age']; //we will echo these into the proper fields

    echo '<tr><td><input type="text" value="<?php echo $id;?>" name="id" disabled/><br/> </td
    <td>First Name:<br/><input type="text" value="<?php echo $FirstName;?>" name="FirstName"/> <br/> </td
    <td>Last Name:<br/><input type="text" value="<?php echo $LastName;?>" name="LastName"/> <br/> </td
    <td>Age:<br/><input type="text" value="<?php echo $Age;?>" name="Age"/> </br>
    <input type="submit" value="submit changes"/></td</tr>';
    }
    echo "</table>";

    // close connection
    mysql_close($con);
    ?>

    <?php
    echo "</form>
    </body>
    </html>";
    ?>
    patriic48@gmail.com, Dec 5, 2012
    #1
    1. Advertising

  2. patriic48@gmail.com

    heff

    Joined:
    Jan 3, 2013
    Messages:
    1
    You've probably solved this by now, but here goes anyway.
    Your GET request should be $id=$_GET['id'];
    heff, Jan 3, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. *** HAWK

    PHP MySQL problems

    *** HAWK, Oct 25, 2003, in forum: Computer Support
    Replies:
    3
    Views:
    598
    HamMan
    Oct 25, 2003
  2. Jamin Agosti

    Re: Free PHP/MySQL webspace

    Jamin Agosti, Dec 8, 2003, in forum: Computer Support
    Replies:
    0
    Views:
    451
    Jamin Agosti
    Dec 8, 2003
  3. JD
    Replies:
    13
    Views:
    1,463
    relic
    Jul 18, 2004
  4. EVS
    Replies:
    0
    Views:
    1,837
  5. EVS
    Replies:
    0
    Views:
    1,648
Loading...

Share This Page