Jump to content

[SOLVED] wont insert anything into my mysql database


laron

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

plesk.png

Link to comment
Share on other sites

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.";
	}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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;}
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.