wooowooo Posted December 24, 2007 Share Posted December 24, 2007 Hi I am trying to create a page which will take session information and allow the user to update there record in the mysql database my friend gave me the following code but it wont work, anyone got any ideas whats wrong with it? Many thanks // Connect to server and select databse. mysql_connect("$host", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if($_POST['Submit']){ // Get parameters from form. $username=$_POST['username']; $forname=$_POST['forname']; $password=$_POST['password']; // Do update statement. mysql_query("update week9 set username='$username', forname='$forname', password='$password'"); // Close database connection. mysql_close(); } ?> <!-- END OF PHP CODES AND START HTML TAGS --> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>"> <p>Username : <!-- name of this text field is "name" --> <input name="name" type="text" id="username" value="<? echo $row['username']; ?>"/> <br /> Forname : <!-- name of this text field is "email" --> <input name="email" type="text" id="forname" value="<? echo $row['forname']; ?>"/> <br /> Password: <!-- name of this text field is "tel" --> <input name="tel" type="text" id="password" value="<? echo $row['password']; ?>"/> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/83000-edit-a-record/ Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 What does won't work mean? Are you getting any errors? What are they? Link to comment https://forums.phpfreaks.com/topic/83000-edit-a-record/#findComment-422157 Share on other sites More sharing options...
revraz Posted December 24, 2007 Share Posted December 24, 2007 You have ID and NAME either mixed up in your INPUT statements or you're using them wrong. The NAME needs to match the $_POST['variable'] name you used for the data to pass. Link to comment https://forums.phpfreaks.com/topic/83000-edit-a-record/#findComment-422181 Share on other sites More sharing options...
p2grace Posted December 24, 2007 Share Posted December 24, 2007 The first thing that stuck out to me was you're not specifying what record you want to update. You have: // Do update statement. mysql_query("update week9 set username='$username', forname='$forname', password='$password'"); Should be something like: // Do update statement. mysql_query("UPDATE `week9` SET `username`= '$username', `forname` = '$forname', `password` = '$password' WHERE `id` = '$id' "); Fix that first then post any errors. Link to comment https://forums.phpfreaks.com/topic/83000-edit-a-record/#findComment-422183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.