captain_scarlet87 Posted March 8, 2010 Share Posted March 8, 2010 Hi, I'm having problems trying to edit data from a table in my database. This is the error that appears: An error occurred in script 'C:\wamp\www\html\edit_form.php' on line 12: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) This is therefore relating to this piece of code: <table border=1> <tr> <td align=center>Form Edit Employees Data</td> </tr> <tr> <td> <table> <?php $order = "SELECT username FROM users where username='$id'"; require_once ('./includes/config.inc.php'); $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> The weird thing is that this bit of the code connects correctly to the database using the same instruction require_once ('./includes/config.inc.php'); and displays all the usernames so there shouldn't be a problem with the config.inc.php file. <?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'); ?> This the final apart of the code, just incase it is needed: <?php //edit_data.php require_once ('./includes/config.inc.php'); $order = "UPDATE users SET username='$username', WHERE username='$id'"; mysql_query($order); header("location:edit.php"); ?> Please help! Thanks. Link to comment https://forums.phpfreaks.com/topic/194484-editing-data-in-db/ Share on other sites More sharing options...
Catfish Posted March 8, 2010 Share Posted March 8, 2010 from your working code: require_once ('../mysql_connect.php'); // Connect to the database. thisis not found in the non-working code. config.inc.php would not be connecting you to the database. mysql_connect.php would be. Link to comment https://forums.phpfreaks.com/topic/194484-editing-data-in-db/#findComment-1022941 Share on other sites More sharing options...
captain_scarlet87 Posted March 8, 2010 Author Share Posted March 8, 2010 Cheers that worked! Can't believe I missed that, copied and pasted the wrong line. However I have now moved on to another problem This time the text box appears from edit_form.php however the username is not already filled in as the value that can be changed. When I fill in the box with a changed username it takes me back to the edit.php with the list of usernames that haven't been altered. Any ideas why? Link to comment https://forums.phpfreaks.com/topic/194484-editing-data-in-db/#findComment-1022959 Share on other sites More sharing options...
captain_scarlet87 Posted March 9, 2010 Author Share Posted March 9, 2010 bump Link to comment https://forums.phpfreaks.com/topic/194484-editing-data-in-db/#findComment-1023518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.