silverglade Posted August 30, 2011 Share Posted August 30, 2011 I can't get my form to update the database with user personal information. Any help greatly appreciated. Upon submitting the form, it just reloads the page, no information added to the DB. I used the update statement because I want the users to be able to update the info at a later date. Not sure if that was the right thing to do. thank you. <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include('bouncer.php'); $host = ""; $database = ""; $username = ""; $password = ""; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); } else { echo "failed to select database"; } $currentUser = $_SESSION['myusername']; // get user from login and make it current user to use for update statement echo "Login success!<br/>"; echo "Please fill out the form below to add your personal information to the database<br/>"; ////////////////////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['submit'])) { $firstname = mysql_real_escape_string( $_POST['first']); $lastname = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); $gender = mysql_real_escape_string( $_POST['gender']); $result= mysql_query ( "UPDATE users SET firstname = '$firstname', lastname = '$lastname', dob = '$dob', gender='$gender' WHERE username='$currentUser'") or die(mysql_error()); if($result) { echo "your information was updated in the database and is as follows <br/>"; //put the results on the screen echo "<br/> $firstname <br/>"; echo "<br/>$lastname <br/>"; echo "<br>$dob <br/> "; echo ">$gender <br>"; } else { echo "error, could not update your info to the database </br>";//end if result } }//end if sumbit post statement at top ?> <html> <body> <p> </p> <p> </p> <p> <form action="login_successERROR.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="submit" value="Add personal information to database" /> <input type="reset" value="Reset fields" /> </p> </p> </form> <p><a href="index.php">HOME</a></p> <p> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/ Share on other sites More sharing options...
SnapGravy Posted August 31, 2011 Share Posted August 31, 2011 Try <?php if(isset($_POST['submit'])) { $firstname = $_POST['first']; $lastname = $_POST['last']; $dob = $_POST['dob']; $gender = $_POST['gender']; $result = mysql_query("UPDATE users SET firstname = '{$firstname}', lastname = '{$lastname}', dob = '{$dob}', gender='{$gender}' WHERE username = '{$currentUser}'") or die(mysql_error()); if($result) { echo "your information was updated in the database and is as follows<br />"; //put the results on the screen echo "<br />{$firstname}<br />"; echo "<br />{$lastname}<br />"; echo "<br />{$dob}<br />"; echo "<br />{$gender}<br />"; } else { echo "error, could not update your info to the database<br />"; } } ?> <html> <body> <form method="post" target="_self" action=""> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="submit" value="Add personal information to database" /> <input type="reset" value="Reset fields" /> </form> <p><a href="index.php">HOME</a></p> </body> </html> I don't know if this will help you though, I copied your code and edited a little. Make sure you double check your variables and whats going into your database as one symbol or letter can break everything. Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263745 Share on other sites More sharing options...
silverglade Posted August 31, 2011 Author Share Posted August 31, 2011 thank you for that. I still can't see what is wrong, and it doesn't work, but thanks for writing that and helping. Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263747 Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2011 Share Posted August 31, 2011 if(isset($_POST['submit'])) <----- that will never be set because your form does not have a field with a name="submit" attribute. Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263749 Share on other sites More sharing options...
SnapGravy Posted August 31, 2011 Share Posted August 31, 2011 Sharp eyes goes to PFMaBiSmAd Also make sure you got session_start() somewhere for the user, i didnt see it on your page. Might be somewhere external though. Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263750 Share on other sites More sharing options...
silverglade Posted August 31, 2011 Author Share Posted August 31, 2011 thank you SO MUCH you both!! I got it working now and it kicks butt. LOL. God I love php programming but it is the most anal retentive thing I have ever pursued. If I didn't really like it, I never would put myself through this. LOL. Thank you!! Link to comment https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.