Jump to content

updating mysql not working


Sharkadder

Recommended Posts

Hi, i have recently been trying out the update command with mysql but the table will not update, the value just get's reset upon submittion, Also once submittion is pressed, it doesn't see to get forwarded to the url i am telling it to, my code is shown below and i bet theres probably only a few things wrong with it.I am using php to code my page, on the page it's a form with text input values, these text input's get values from the database itself, the idea being that you can then modify these values, press "confirm changes" and the database should then be updated, however this does not seem to happen.The code for my update command is as follows:<form METHOD = "POST"><?php$newline = "<br />";// If the login information is correct do the following;//all these values are values taken from a row in the database and this part is working fineecho "Username : <input type='text' name='Username' value='$row[username]'> ".$newline ;echo "Password : <input type='text' name='Password' value='$row[Password]'> ".$newline ;echo "Forename : <input type='text' name='Forename' value='$row[Forename]'> ".$newline ;echo "Surname : <input type='text' name='Surname' value='$row[surname]'> ".$newline ;echo "Address Line 1 : <input type='text' name='AddressLine1' value='$row[AddressLine1]'> ".$newline ;echo "Address Line 2 : <input type='text' name='AddressLine2' value='$row[AddressLine2]'> ".$newline ;echo "E-mail Address : <input type='text' name='EmailAddress' value='$row[EmailAddress]'> ".$newline ;}?>//updating the actual records doesn't seem to be happening, i tell the variables to equal the post's value but no luck<input type='submit' name='Confirm' value='Confirm Changes'><a href="account.php"><input type='submit' name='Cancel' value='Cancel Changes'></a></form><?phpif ($_POST["submit"] == 'Update') {$username = $_POST['Username'];$password = $_POST['Password'];$forename = $_POST['Forename'];$surname = $_POST['Surname'];$AddressLine1 = $_POST['AddressLine1'];$AddressLine2 = $_POST['AddressLine2'];$EmailAddress = $_POST['EmailAddress'];$SQL = " UPDATE dreamboxsales SET username = $username WHERE Username = '$username'";$resultupdate = mysql_db_query($dbname, "$SQL", $db);//check for errorsif (!$resultupdate) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }echo "Records Updated";}?>Ok as you can see from above the records won't be updated because i have not told them to, only the username. This is for testing, once i cracked username i can then update the rest, any idea why when i modify the value from the username's textbox and press submit it resets itself to the old value? Will i need to call upon a new php file once submit is pressed or what?thanks

Link to comment
Share on other sites

Are you seeing an error? And what does the mysql_db_query() function look like?Also, $username as in "SET username = ~" needs to be in quotes.Finally, you are checking if ($_POST["submit"] == 'Update'), but do you have an input with name="submit" and value="Update"?

Link to comment
Share on other sites

thanks for the reply, i modified my form content and values so that the submit button did indeed have the name submit and the value update, i then tried my code and it still wouldn't work. I then put the username from the SET operation in single quotes and uploaded again, same problem and didn't work.I then decided to go back to my form and values taken from it, i noticed when i did my insert operations upon signup i used the $_REQUEST function instead of $_POST when getting values from forms, i changed that and it still wouldn't work, but i know why it was.I was telling the database to update the username record with the username from the $username variable, if you recall, i am telling the update command to change this variable name depending on the value entered in the form, therefore when the lookup takes place theres no such username. I then added another field to the update query which was to be AddressLine2, i again used the request function instead of post, type in a new value, pressed update and hey presto it worked.Too be honest with you, i don't think allowing people to change username is such a good idea, password maybe, to allow people to update username i will just check the database depending on the user id instead, but anyway's thanks for all the help.My update command is now working good, thanks for spotting the errors.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...