captain_scarlet87 Posted March 9, 2010 Share Posted March 9, 2010 Hi, So far I have managed to display all the current usernames from a table with a link alongside each to edit it. The page it takes you next should display the current username in the text box that can be changed and then submitted, however the text box is empty. I have tried typing in a different username and then submitting it but it doesnt update this in the table. Please help me. edit.php (correctly displays username and edit link: <?php # Script 13.8 - edit.php // Include the configuration file for error management and such. require_once ('./includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'Users'; include ('./includes/header.html'); ?> <table> <tr> <td align="center">Edit Users</td> </tr> <tr> <td> <table border="1"> <?php require_once ('../mysql_connect.php'); // Connect to the database. $order = "SELECT username FROM users"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td>$row[username]</td>"); echo ("<td><a href=\"edit_form.php?id=$row[username]\">Edit</a></td></tr>"); } ?> </table> </td> </tr> </table> <?php include ('./includes/footer.html'); ?> edit_form.php (current username not appearing in text box): <table border=1> <tr> <td align=center>Form Edit Employees Data</td> </tr> <tr> <td> <table> <?php require_once ('../mysql_connect.php'); // Connect to the database. $order = "SELECT username FROM users where username='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="edit_data.php"> <input type="hidden" name="id" value="<?php echo "$row[username]"?>"> <tr> <td>Username</td> <td> <input type="text" name="username" size="20" value="<?php echo "$row[username]"?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> </td> </tr> </table> edit_data.php (not editing the username in the users table): <?php //edit_data.php require_once ('../mysql_connect.php'); // Connect to the database. $order = "UPDATE users SET username='$username', WHERE username='$id'"; mysql_query($order); header("location:edit.php"); ?> Link to comment https://forums.phpfreaks.com/topic/194689-displaying-current-value-and-then-editing-it/ Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Try echoing $row[0]['username'] That should fix your problem Link to comment https://forums.phpfreaks.com/topic/194689-displaying-current-value-and-then-editing-it/#findComment-1023884 Share on other sites More sharing options...
captain_scarlet87 Posted March 10, 2010 Author Share Posted March 10, 2010 Thanks for the reply, I tried using $row[0]['username'] in the edit_forum.php but it now displays ['username'] in the text box. Any further suggestions? Link to comment https://forums.phpfreaks.com/topic/194689-displaying-current-value-and-then-editing-it/#findComment-1023964 Share on other sites More sharing options...
captain_scarlet87 Posted March 10, 2010 Author Share Posted March 10, 2010 Any ideas? Link to comment https://forums.phpfreaks.com/topic/194689-displaying-current-value-and-then-editing-it/#findComment-1024190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.