ashrobbins87 Posted March 23, 2009 Share Posted March 23, 2009 I have a form which displays user data from the database and I want to be able to let the user change it and resubmit it to the database. This is the code for the form.... I know that $id, $f, $s and $u all have data in them because they display on the page, but I cannot update the new data that is entered in the form. I'm not sure if this is a PHP or MySQL problem. Any help appreciated! <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\" value=\""; echo @$_POST['upload'] ? $_POST['upload'] : ''; echo "\"> <table> <tr><td>First Name: </td><td><input type=\"text\" name=\"firstname\" size=\"20\" value=".$f." /></tr> <tr><td>Surname: </td><td><input type=\"text\" name=\"surname\" size=\"20\" value=".$s." /></tr> <tr><td>Username: </td><td><input type=\"text\" name=\"username\" size=\"20\" value=".$u." /></tr> <tr><td>New Password: </td><td><input type=\"text\" name=\"newpassword\" size=\"20\" value=\"Enter New Password\" /></tr> <tr><td>Re-enter Password: </td><td><input type=\"text\" name=\"confirmpassword\" size=\"20\" value=\"Confirm New Password\" /></tr> </table> <br/><br/> "; $new_f = $_POST['firstname']; $new_s = $_POST['surname']; $new_u = $_POST['username']; $new_p = $_POST['newpassword']; $conf_p = $_POST['confirmpassword']; if($new_f) { if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $updateUser_sql = "UPDATE cms_users SET firstname ='".$new_f."' AND surname ='".$new_s."' AND username ='".$new_u."' WHERE id = '".$id."'"; $updateUser_res = mysqli_query($mysqli, $updateUser_sql); if ($updateUser_res === TRUE) { echo "Update Successful"; header ("Location: user.php"); } else { printf("Could not update page: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } } echo"<table> <tr> <td><input type=\"submit\" name=\"update\" value=\"Update User\"></td> <td><a href=\"javascript:eventWindow('cms/deletevalidation.php');\"><input type=\"submit\" name=\"delete\" value=\"Delete\"></a></td> </tr> </table></form>"; Link to comment https://forums.phpfreaks.com/topic/150706-update-problems/ Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 This will fail: echo "Update Successful"; header ("Location: user.php"); You cannot send ANYTHING to the browser when using header() Link to comment https://forums.phpfreaks.com/topic/150706-update-problems/#findComment-791698 Share on other sites More sharing options...
waynew Posted March 23, 2009 Share Posted March 23, 2009 You're not showing us all of the code. Link to comment https://forums.phpfreaks.com/topic/150706-update-problems/#findComment-791706 Share on other sites More sharing options...
rhodesa Posted March 23, 2009 Share Posted March 23, 2009 are there no mysql errors printed? Link to comment https://forums.phpfreaks.com/topic/150706-update-problems/#findComment-791708 Share on other sites More sharing options...
waynew Posted March 23, 2009 Share Posted March 23, 2009 Is the JS confirmation that you have set on your submit button working? We'll need to know more about what actually happens when you attempt to update this form. Also: $updateUser_res = mysqli_query($mysqli, $updateUser_sql) or trigger_error(mysqli_error($mysqli_link)); Link to comment https://forums.phpfreaks.com/topic/150706-update-problems/#findComment-791711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.