laron Posted April 23, 2007 Share Posted April 23, 2007 I'm obiously doing something wrong but cant see it. (for now the code is sloppy... but here it is) main php page <?php include("variables.php"); include("connect.php"); if (strlen($username) < 4){ //if username is to short then echo this echo "Username is to short. It must be more than 3 characters long. Please go back."; } else{ if(strlen($password) > 6 && strlen($password) < 20){ if($email == "" || $firstname == "" || $lastname == "" || $address == "" || $city == "" || $zip == ""){ echo "Not all forms are filled in, please go back."; } else{ if($password != $confirmpassword){ echo "Passwords don't match, please go back."; } else{ if($email != $confirmemail){ echo "E-mail addresses don't match, please go back."; } else{ if($agree == "agree"){ echo "all is good."; include("insert.php"); } else{ echo "You disagree with DFG4U Rules. Please go back, or return to the <a href=\"http://www.dfg4u.com\">Debt Freedom Group 4 U homepage.</a>"; } } } } } else{ echo "Password does not match specifications. Please go back."; } } ?> files that are included in main php page connect.php <?php $dbhost = "localhost"; $dbuser = "dfgadmin"; $dbpass = "laron5453"; $dbname = "dfgusers"; $con = mysql_connect($dbhost,$dbuser,$dbpass); $db = mysql_select_db($dbname,$con); if(!$con){ echo "Error connecting: "; mysql_error(); die;} if(!$db){ echo "Error selecting database."; mysql_error(); die;} ?> variables.php <?php //grabs data from form, inputs in variables $username = $_POST["username"]; $password = $_POST["password"]; $confirmpassword = $_POST["confirmpassword"]; $email = $_POST["email"]; $confirmemail = $_POST["confirmemail"]; $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $address = $_POST["address"]; $city = $_POST["city"]; $state = $_POST["state"]; $zip = $_POST["zip"]; $gender = $_POST["gender"]; $agree = $_POST["agree"]; $datestart = date(); $dateend = date(); $status = "0"; ?> insert.php <?php $sql = "INSERT INTO users(username,password,email,firstname,lastname,address,city,state,zip,gender,datestart,dateend,status) VALUES ('".$username."','".$password."','".$email."','".$firstname."','".$lastname."','".$address."','".$city."','".$state."','".$gender."','".$datestart."','".$dateend."','".$status."')"); mysql_query($sql,$con); mysql_close($con); ?> thanks Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/ Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 in variables.php, is $_POST["agree"] being set ? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-236453 Share on other sites More sharing options...
laron Posted April 24, 2007 Author Share Posted April 24, 2007 yes Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-236701 Share on other sites More sharing options...
sanfly Posted April 24, 2007 Share Posted April 24, 2007 Gosh, thats a lot of pages you have there! in your insert.php change this mysql_query($sql,$con); to this mysql_query($sql,$con) or die(mysql_error()); Does it return any error messages? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-236704 Share on other sites More sharing options...
rcorlew Posted April 24, 2007 Share Posted April 24, 2007 Try changing your variables set in your sql query to this {'$variable'} instead of '".$username."' Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-236705 Share on other sites More sharing options...
laron Posted April 24, 2007 Author Share Posted April 24, 2007 ok i've dont the above, and the code runs with no mysql errors(or none shown), but when i check the database, no data has been added. Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237468 Share on other sites More sharing options...
laron Posted April 24, 2007 Author Share Posted April 24, 2007 ok so ive changed it a little bit. insead of inserting the "insert.php" page into the last if statement, i just took the code from that page and stuck it in the if statement.(confused?) ... else{ if($email != $confirmemail){ echo "E-mail addresses don't match, please go back."; } else{ if($agree == "agree"){ echo "all is good."; $sql = "INSERT INTO users(username,password,email,firstname,lastname,address,city,state,zip,gender,datestart,dateend,status) VALUES ('$username','$password','$email','$firstname','$lastname','$address','$city','$state','$gender','$datestart','$dateend','$status')"); mysql_query($sql,$con) or die(mysql_error()); mysql_close($con); //include("insert.php"); <<--took the contents of this page and put it above ^^ } else{ echo "You disagree with DFG4U Rules. Please go back, or return to the <a href=\"http://www.dfg4u.com\">Debt Freedom Group 4 U homepage.</a>"; } } } ... when i hit the submit button it directs me to this main php page but nothing is on it, its blank. no echo "all is good, nothing". and once again nothing is in the database. whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237489 Share on other sites More sharing options...
sanfly Posted April 24, 2007 Share Posted April 24, 2007 Hmmm, well I cant immediately see why you shouldnt get anything returned, unless its not even getting into the else{} part of the code. Can you post the if{} part as well? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237531 Share on other sites More sharing options...
laron Posted April 24, 2007 Author Share Posted April 24, 2007 yes, ok here is the main php page that you get directed to after you hit submit on the previous page. <?php include("variables.php"); include("connect.php"); if (strlen($username) < 4){ //if username is to short then echo this echo "Username is to short. It must be more than 3 characters long. Please go back."; } else{ if(strlen($password) > 6 && strlen($password) < 20){ if($email == "" || $firstname == "" || $lastname == "" || $address == "" || $city == "" || $zip == ""){ echo "Not all forms are filled in, please go back."; } else{ if($password != $confirmpassword){ echo "Passwords don't match, please go back."; } else{ if($email != $confirmemail){ echo "E-mail addresses don't match, please go back."; } else{ if($agree == "agree"){ echo "all is good."; //include("insert.php"); } else{ echo "You disagree with DFG4U Rules. Please go back, or return to the <a href=\"http://www.dfg4u.com\">Debt Freedom Group 4 U homepage.</a>"; } } } } } else{ echo "Password does not match specifications. Please go back."; } } ?> from this code, that if statment is working, it does say all is good, but nothing is being sent to the database the insert code is(insert.php)... <?php $sql = "INSERT INTO users(username,password,email,firstname,lastname,address,city,state,zip,gender,datestart,dateend,status) VALUES ('$username','$password','$email','$firstname','$lastname','$address','$city','$state','$gender','$datestart','$dateend','$status')"); mysql_query($sql,$con) or die(mysql_error()); mysql_close($con); ?> does it have something to do with in the database.... ive basically use default setting. (screenshot) Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237542 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Okay, ive added a few debugging lines in here. When you run the code, you should get 6 messages come up, all numbered 1-6, if everything is okay. Run the code, then report back on what you see <?php include("variables.php"); include("connect.php"); echo "1. checking username long enough<br>"; // Remove this line later if (strlen($username) < 4){ //if username is to short then echo this echo "Username is to short. It must be more than 3 characters long. Please go back."; } else{ echo "2. checking password correct length<br>"; // Remove this line later if(strlen($password) > 6 && strlen($password) < 20){ echo "3. checking all fields filled in<br>"; // Remove this line later if($email == "" || $firstname == "" || $lastname == "" || $address == "" || $city == "" || $zip == ""){ echo "Not all forms are filled in, please go back."; } else{ echo "4. checking passwords match<br>"; // Remove this line later if($password != $confirmpassword){ echo "Passwords don't match, please go back."; } else{ echo "5. checking email addresses match<br>"; // Remove this line later if($email != $confirmemail){ echo "E-mail addresses don't match, please go back."; } else{ echo "6. checking agreed to conditions<br>"; // Remove this line later if($agree == "agree"){ echo "all is good."; //include("insert.php"); } else{ echo "You disagree with DFG4U Rules. Please go back, or return to the <a href=\"http://www.dfg4u.com\">Debt Freedom Group 4 U homepage.</a>"; } } } } } else{ echo "Password does not match specifications. Please go back."; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237561 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 the result 1. checking username long enough 2. checking password correct length 3. checking all fields filled in 4. checking passwords match 5. checking email addresses match 6. checking agreed to conditions all is good. Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237565 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Maybe its something to do with fields having the same name as reserved words in mysql (im not going to go through them all and check) try putting your table and field names in backquotes, eg: <?$sql = "INSERT INTO `users` (`username`,`password`,`email`,`firstname` etc....... ?> Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237576 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 uhg this is killin me ???, no success. Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237582 Share on other sites More sharing options...
AndyB Posted April 25, 2007 Share Posted April 25, 2007 Take a careful look at your insert query. You have 13 fields and 12 values (zip gets nothing). I can't think why you're not seeing the mysql error message because that should have thrown one. Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237598 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Take a careful look at your insert query. You have 13 fields and 12 values (zip gets nothing). I can't think why you're not seeing the mysql error message because that should have thrown one. Hmm, I didnt even bother counting that because I assumed an error should be shown from the die() function Is it possible that error reporting is turned off in the php.ini file? laron, is this on a home computer or hosted server? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237600 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 hosted server Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237605 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Maybe you should check with your host about error reporting So as Andy pointed out, does adding '$zip', in the the appropriate place in your values solve the problem? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237608 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 heres what i changed insert to, and changed database as well. <?php $sql = "INSERT INTO users(`username,password,email,firstname,lastname,address,city,state,zip,gender,status) VALUES ('$username','$password','$email','$firstname','$lastname','$address','$city','$state','$zip','$gender','$datestart','$status')"); mysql_query($sql,$con) or die(mysql_error()); mysql_close($con); ?> still no sucess, i will look into the php.ini to see about error reporting (where is this file located) Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237619 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 You usually cant access the file if you have a server hosted by someone else you can try this though make a page called phpinfo.php put the following code inside that page <? phpinfo(); ?> Upload to your server and run the page This will show you information about your php installation under "CONFIGURATION PHP CORE" look for error_reporting there should be a number after it. What is it? NB: When you have finished remove the phpinfo.php page off your server to prevent anyone else seeing your configuration Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237622 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 2039 Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237629 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 display_errors is off though .... under configuration php core this the problem? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237631 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Hmmm, well thats the same as I have, and error reporting works fine for me. Okay, how about a different tack Whats the content of your connect.php file (be sure to remove your username and password, replace with ******* or something) Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237633 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 here is the code for connect.php <?php $dbhost = "localhost"; $dbuser = "***"; $dbpass = "***"; $dbname = "***"; $con = mysql_connect($dbhost,$dbuser,$dbpass); $db = mysql_select_db($dbname,$con); if(!$con){ echo "Error connecting: "; mysql_error(); die;} if(!$db){ echo "Error selecting database."; mysql_error(); die;} ?> Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237636 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 display_errors is off though .... under configuration php core this the problem? That could be it. I dont know that much about php.ini but will have a play around and see if that setting makes a difference to me. In the meantime, I suggest that you get intouch with your webhost and ask if there is a way to get that switched on for your account. Alternatively if anyone else can provide further help..... Hmm, does anyone know if you can change php settings in htaccess? or something similar? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237640 Share on other sites More sharing options...
laron Posted April 25, 2007 Author Share Posted April 25, 2007 why it wont work, beats me... anyone else, suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/48364-solved-wont-insert-anything-into-my-mysql-database/#findComment-237646 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.