bano6010 Posted February 4, 2009 Share Posted February 4, 2009 Hello everyone, I am trying to edit records in my database through php. I am currently using MySQL version 5.0.67. On one page I have all of the records I want to be able to edit properly listing. I made a link to my edit page using the ID for the record in the url. The link looks like this: <a href=edit.php?id=<? echo $id; ?> Where $id is set to: $id = $row[id]; On the edit page, this is my code: <? $query = "SELECT * FROM `officers` WHERE id='$id'"; $result = mysql_query($query) or die("No Record Found!"); while ($row = mysql_fetch_array($result)) { $type=$row['type']; $firstname=$row['firstname']; $lastname=$row['lastname']; } ?> <form action="change.php" method="post"> <table border="1" bordercolor=FFFFFF cellpadding="3"> <tr> <td>Officer:</td> <td><? echo "$type"; ?></td> </tr> <tr> <td>First Name:</td> <td bordercolor=EEEEEE><input type="text" value="<? echo "$firstname"; ?>" name="firstname" /></td> </tr> <tr> <td>Last Name:</td> <td bordercolor=EEEEEE><input type="text" value="<? echo "$lastname"; ?>" name="firstname" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Save Changes" /></td> </tr> </table> </form> After clicking the link it brings me to the edit page but the form is empty. I want the form to show the record for the ID that is used in the link on the first page. I think I need to define $id somewhere on the edit page but am unsure how or where to. Sorry my code is not in a code block, I do not know how to do that. Any help would be greatly appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/143788-solved-using-id-to-call-up-record/ Share on other sites More sharing options...
Maq Posted February 4, 2009 Share Posted February 4, 2009 1) Never use short tags to start PHP, always use <?php. 2) You need to read up on the GET method. 3) You need to grab the value from the URL before you use it in your query: $id = $_GET['id']; $query = "SELECT * FROM `officers` WHERE id='$id'"; $result = mysql_query($query) or die("No Record Found!"); 4) Use tags next time. Quote Link to comment https://forums.phpfreaks.com/topic/143788-solved-using-id-to-call-up-record/#findComment-754414 Share on other sites More sharing options...
bano6010 Posted February 4, 2009 Author Share Posted February 4, 2009 That did it. Thanks so much. Ill try to do some more research first next time. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/143788-solved-using-id-to-call-up-record/#findComment-754420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.