fonecave Posted May 3, 2008 Share Posted May 3, 2008 Why is this code not adding anything? It connects ok but doesnt add a recordset <?php if (isset ($_POST['submit'])) { $name=$_POST["name"]; $address=$_POST["address"]; $password=$_POST["password"]; $con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members if (!$con) { die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error()); } mysql_select_db("fonecave_00001", $con); mysql_query("INSERT INTO members (name, email, password) VALUES ('$name', '$address', '$password')"); echo "Registration Complete!"; ?> Quote Link to comment Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 try this <?php if (isset ($_POST['submit'])) { $con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members if (!$con) { die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error()); } mysql_select_db("fonecave_00001", $con); mysql_query("INSERT INTO members (name, email, password) VALUES ('$_POST[name]', '$_POST[address]', '$_POST[password]')"); echo "Registration Complete!"; ?> Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 I Have tried that i get this Parse error: syntax error, unexpected T_ELSE in /www/110mb.com/f/o/n/e/c/a/v/e/fonecave/htdocs/login.php on line 438 Quote Link to comment Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 <?php if (isset ($_POST['submit'])) { $con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members if (!$con) { die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error()); } mysql_select_db("fonecave_00001", $con); mysql_query("INSERT INTO members (name, email, password) VALUES ('$_POST[name]', '$_POST[address]', '$_POST[password]')"); echo "Registration Complete!"; } ?> what about now? Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 i get the successful text echoed on the page, but nothing appears in the database not even blank records but it must be connecting fine can you think of anything else Quote Link to comment Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 Could you post your form? Quote Link to comment Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Share Posted May 3, 2008 Sure the DB Table isnt Members? and not members like you wrote. Sounds stupid but could be it. Have you set the fields to the right settings? Like..your not trying to isntert text into an ENUM field etc. screenshot of the DB? Form HTML? Hope that helps. Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 ** Deleted for security purposes ** Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 Table structure for: Members Field Name Type Null Key Default Extra name varchar(20) No Unknown email varchar(30) No PRI password varchar(20) No Ihave tried members and Members neither work Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 I Think there was an error with the db i have receated the table and it now work, What code would i use to search for a duplicate email address before adding? Quote Link to comment Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Share Posted May 3, 2008 This is raw code from one of my projects: $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email' AND status='Alive'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$reg_username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo ""; if($email_check > 0){ $message= "*This email address has already been used by another player!"; unset($email); } if($username_check > 0){ $message="*That desired username is already in use!"; unset($reg_username); } Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 ok i get this now: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/110mb.com/f/o/n/e/c/a/v/e/fonecave/htdocs/login.php on line 406 $sql_email_check = mysql_query("SELECT email FROM members WHERE email='$address'"); $email_check = mysql_num_rows($sql_email_check); //line406 if($email_check > 0) { echo 'Registration Failed, Already Registered!'; } else { mysql_select_db("fonecave_00001", $con); mysql_query("INSERT INTO members (name, email, password) VALUES ('$name', '$address', '$password')"); echo "Registration Complete!";} Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 is this because the result is 0? Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 3, 2008 Share Posted May 3, 2008 Replace: $sql_email_check = mysql_query("SELECT email FROM members WHERE email='$address'"); With this: $query = "SELECT email FROM members WHERE email='$address'"; $sql_email_check = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); If it's not obvious what needs to be fixed from the resulting error, post more information. Quote Link to comment Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 Thanks for the tip, i must use that more. Heres what i got... Error: No database selected with query SELECT email FROM members WHERE email='user@fonecave.co.uk' it was obvious what i had to do so now fixed! Thank You all so much for your help yet again! Quote Link to comment 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.