Ph0eNiX223 Posted September 19, 2007 Share Posted September 19, 2007 Hi, I made a simple script where users can change their username and password. When they click submit the data will be changed. It gives me a confirmation that it has been updated but it doesn't! Here's the code: <?php include('config2.php'); $nusername = $_POST['username']; $npassword = $_POST['password']; $id = $_REQUEST['id']; $sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error()); echo "Page has been successfully changed! Please <a href='login.php'>log in</a> with your new user details "; mysql_close(); ?> And here is the form: <?php session_start(); if($_SESSION['auth'] == true) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="accchange.php" method="POST"> Type your new username: <input type="text" value="<?= $_SESSION['username'] ?>" name="username" /><br /> Type your new password: <input type="password" name="password" /><br /> <input type="submit" value="submit" name="submit" /> </form> <?php } else { echo "You're not logged in. Make sure you're logged in."; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/ Share on other sites More sharing options...
chocopi Posted September 19, 2007 Share Posted September 19, 2007 Your not actually running the query Replace: $sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error()); with $sql = "UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'" mysql_query($sql) or die(mysql_error()); Hope that helps ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/#findComment-351175 Share on other sites More sharing options...
The Little Guy Posted September 19, 2007 Share Posted September 19, 2007 Your not actually running the query Replace: $sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error()); with $sql = "UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'" mysql_query($sql) or die(mysql_error()); Hope that helps ~ Chocopi They are both the same thing.. he is running the query $nusername $nupassword $id echo all three of these out, and make sure there is something stored in them. Quote Link to comment https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/#findComment-351177 Share on other sites More sharing options...
chocopi Posted September 19, 2007 Share Posted September 19, 2007 No his method was just storing the query to a variable so it was not being executed, wheres mine stores what needs to be done in a variable and then executes that variable by using mysql_query ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/#findComment-351182 Share on other sites More sharing options...
The Little Guy Posted September 19, 2007 Share Posted September 19, 2007 I do it both ways all the time, and they both work perfectly fine. his way executes then stores the result in a variable. Quote Link to comment https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/#findComment-351304 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.