tom.hill Posted December 23, 2007 Share Posted December 23, 2007 Hi Guys, for some reason this code is not working, i dont suppose anyone can spot an obvious error? many thanks in advance. <?php // Check if session is not registered , redirect back to login page. include('../includes/checklogin.php'); // Connect to server and select database include('../db_login.php'); $oldusername = $_GET['username']; // username and password sent from form $username =$_POST['username']; $password =md5($_POST['password']); // Insert data into mysql $query = "UPDATE tusers SET username = '$username' , password = '$password' WHERE username = '$oldusername'"; $result = mysql_query($query); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='administration.php'>Back to admin</a>"; } else { echo "ERROR <BR>"; // for testing echo "old $oldusername <BR>"; echo "new $username <BR>"; echo "pass $password <BR>"; } ?> my echo's for testing display the correct information but will not update the data in the database!!! Quote Link to comment https://forums.phpfreaks.com/topic/82956-solved-update-statement-problem/ Share on other sites More sharing options...
tom.hill Posted December 23, 2007 Author Share Posted December 23, 2007 my include statement for the db login was wrong!!!! all day working on it, only to then post it here and fix it in 2 minutes of posting! thanks anyway guys. Quote Link to comment https://forums.phpfreaks.com/topic/82956-solved-update-statement-problem/#findComment-421916 Share on other sites More sharing options...
shocker-z Posted December 23, 2007 Share Posted December 23, 2007 Great news that you fixed it but for future issues have a look what i posted just after you had replyed. change $result = mysql_query($query); to $result = mysql_query($query) or die('Error updating: '.mysql_error()); That will return what error you have. The syntax looks fine but could be a column name or somthing. This is a very very useful debugging code to use! Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/82956-solved-update-statement-problem/#findComment-421918 Share on other sites More sharing options...
tom.hill Posted December 23, 2007 Author Share Posted December 23, 2007 thanks liam great advice! Quote Link to comment https://forums.phpfreaks.com/topic/82956-solved-update-statement-problem/#findComment-421944 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.