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 [email protected] - 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!"; ?> Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/ 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 [email protected] - 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!"; ?> Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532335 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 Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532337 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 [email protected] - 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? Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532338 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 Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532340 Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 Could you post your form? Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532342 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. Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532344 Share on other sites More sharing options...
fonecave Posted May 3, 2008 Author Share Posted May 3, 2008 ** Deleted for security purposes ** Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532350 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 Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532352 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? Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532355 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); } Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532358 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!";} Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532384 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? Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532389 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. Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532394 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='[email protected]' it was obvious what i had to do so now fixed! Thank You all so much for your help yet again! Link to comment https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/#findComment-532400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.