silverglade Posted July 26, 2010 Share Posted July 26, 2010 Hi, my database form doesn't work, I get no errors, please if anyone could help me by checking to see if I have any errors I'd greatly appreciate it. Thanks. Derek Here is the code <?php include("connect1.php"); if (!empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['confirm']) && !empty($_POST['submit'])) { // Declare Variables $Email = mysql_real_escape_string($_POST['email']); $Password = mysql_real_escape_string($_POST['password']); $Confirm = mysql_real_escape_string($_POST['confirm']); // Encrypt passwords with md5 encryption $Password = md5($Password); $Confirm = md5($Confirm); if($Password != $Confirm) { echo "<br>The two passwords did not match<br>"; } else { // Check if the email already exists in database $query = "SELECT * FROM users WHERE Email = '$Email' "; $results = mysql_num_rows(mysql_query($query)); if ($results > 0) { echo "sorry email already exists"; } else { // Insert information to the database mysql_query("UPDATE users SET Password='$Password' WHERE Email='$Email'"); //Send them to login header("Location:http://dragonofsun.com/success.html"); } }//else }//if ?> <!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>Sign up page</title> <style type="text/css"> body { background-color: #000000; color: #ffffff; } #center_div { vertical-align: middle; } a:link, a:hover, a:active, a:visited { color: gold; } .style1 { font-size: larger; color: #FFD700; } </style> </head> <body> <p align="center" class="style1">Realm of the Sun Dragon sign up form</p> <table align="center" cellpadding="10px"><tr><td> Please enter your email: <form action="signup.php" method="POST" > <input type="text" name="email"></td></tr> <tr><td> Please enter your password:<br> <input type="password" name="password"> </td></tr> <tr><td>Please Confirm that Password:<br> <input type="password" name="confirm"></td></tr> <tr><td><input type="submit" name="submit" value="Sign Up"></form></td></tr></table> <br /><br /> <center><font face=Arial>Copyright © 2010, <a target=_blank href="http://derekvanderven.com"> by Derek Van Derven</a></font></center></body></html> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/ Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 Well... what does happen? You should always develop with this at the top of the page: error_reporting(E_ALL); Something could be throwing an error and you might not know. Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091180 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 thanks. I put that at the top and I get no errors. The post is posting all the right values, so the form is working, it's just not getting into the database, and I'm assuming it's connecting to the database, because I don't get any errors. So it must be my code. Any more help greatly appreciated. Thanks. Derek Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091181 Share on other sites More sharing options...
PravinS Posted July 26, 2010 Share Posted July 26, 2010 You want to insert new record or want to update existing record. If you want to enter new record then you need to write INSERT query instead of UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091182 Share on other sites More sharing options...
FuThAr Posted July 26, 2010 Share Posted July 26, 2010 in your code there you say "if mail doesn't exists, update the row where the mail is $email" ... it's impossible, so he can't update: try an INSERT query INSERT INTO users (password,Email) VALUES ( $Password , $Email); Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091185 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 Ok it still does not work, thank you for helping. Here is the code as it is written now. Thanks. Derek <?php include("connect1.php"); error_reporting(E_ALL); echo "<pre>".print_r($_POST, 1)."</pre>"; if (!empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['confirm']) && !empty($_POST['submit'])) { // Declare Variables $Email = mysql_real_escape_string($_POST['email']); $Password = mysql_real_escape_string($_POST['password']); $Confirm = mysql_real_escape_string($_POST['confirm']); // Encrypt passwords with md5 encryption $Password = md5($Password); $Confirm = md5($Confirm); if($Password != $Confirm) { echo "<br>The two passwords did not match<br>"; } else { // Check if the email already exists in database $query = "SELECT * FROM users WHERE Email = '$Email' "; $results = mysql_num_rows(mysql_query($query)); if ($results > 0) { echo "sorry email already exists"; } else { // Insert information to the database mysql_query("INSERT INTO users (password,email) VALUES ( $Password , $Email)"); //Send them to login header("Location:http://dragonofsun.com/success.html"); } }//else }//if ?> <!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>Sign up page</title> <style type="text/css"> body { background-color: #000000; color: #ffffff; } #center_div { vertical-align: middle; } a:link, a:hover, a:active, a:visited { color: gold; } .style1 { font-size: larger; color: #FFD700; } </style> </head> <body> <p align="center" class="style1">Realm of the Sun Dragon sign up form</p> <table align="center" cellpadding="10px"><tr><td> Please enter your email: <form action="signup.php" method="POST" > <input type="text" name="email"></td></tr> <tr><td> Please enter your password:<br> <input type="password" name="password"> </td></tr> <tr><td>Please Confirm that Password:<br> <input type="password" name="confirm"></td></tr> <tr><td><input type="submit" name="submit" value="Sign Up"></form></td></tr></table> <br /><br /> <center><font face=Arial>Copyright © 2010, <a target=_blank href="http://derekvanderven.com"> by Derek Van Derven</a></font></center></body></html> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091186 Share on other sites More sharing options...
FuThAr Posted July 26, 2010 Share Posted July 26, 2010 let's look at the error: $res = mysql_query("INSERT INTO users (password,email) VALUES ( '$Password' , '$Email')"); if ( !$res ) { echo "** debug: " . mysql_error() . " ** </br />"; } else { echo "**debug: " . mysql_affected_rows() . " affected rows ** </br />"; } Alberto Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091190 Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 Because the values you're inserting are not numeric they need quotes around them. mysql_query("INSERT INTO users (password,email) VALUES ('$Password', '$Email')"); Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091191 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 HAHA IT WORKS!! THANKS EVERYONE FOR YOUR TIME AND HELPING!! now i can go to SLEEP OMG> haha. thanks. Derek :D :D Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091192 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 crud! Its not redirecting to my success page! Am I using the php header function correctly please? Thanks. Derek. I'm almost there. lol Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091195 Share on other sites More sharing options...
FuThAr Posted July 26, 2010 Share Posted July 26, 2010 from php.net Remember that header() must be called before any actual output is sent, either by normal HTML tags in your code there is output instead. Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091197 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 Thank you, how would I redirect them to success.html after they do the form? please. Derek Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091198 Share on other sites More sharing options...
FuThAr Posted July 26, 2010 Share Posted July 26, 2010 there are a lot of ways: simply switch off every output before header() call, or if you can't ... use javascript, with client redirection echo "<script type='text/javascript'>window.location='http://your.success.page.html'</script>"; Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091199 Share on other sites More sharing options...
silverglade Posted July 26, 2010 Author Share Posted July 26, 2010 AWESOME thank you it works now Quote Link to comment https://forums.phpfreaks.com/topic/208898-my-code-wont-insert-data-from-form-into-the-database/#findComment-1091217 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.