PHP MySQL UPDATE

Discussion in 'Software' started by [email protected], Dec 5, 2012.

  1. patriic48@gmail.com

    [email protected]

    Joined:
    Oct 13, 2012
    Messages:
    9
    Likes Received:
    0
    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>";
    ?>
     
    [email protected], Dec 5, 2012
    #1
    1. Advertisements

  2. patriic48@gmail.com

    heff

    Joined:
    Jan 3, 2013
    Messages:
    1
    Likes Received:
    0
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.