Jump to content

[SOLVED] PHP Inserting Values of "1" into DB


stublackett

Recommended Posts

FAO Forum MOD's although It may appear as a double post, Its a totally different subject, So if needs be delete my other post!!

 

My problem is the script below is the register.php form handler that is pressed on ACTION of the Register button on my site

It runs through the validation and the INSERT to an extent, But when I look at the data in the Database it is significantly filled with "1"'s

Has anyone any idea as to why this is the case?

 

Thanks

 

<?php
####################################################################
################ DATABASE CONNECT ##############################
####################################################################
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$dbname = "login";
$db_table = "users";


# STOP HERE
####################################################################
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($dbname,$db);
?> 
<?php #Script register.php By Stuart Blackett - stuartblackett@googlemail.com
$username = $_POST['username'];
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$password = $_POST['password1'];
$level = $_POST['level'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$zip = $_POST['zip'];

if (isset($_REQUEST['Submit']))
// Check $_POST['username'] and strip any slashes
if (!empty($_POST['username'])) {
$username = stripslashes($_POST['username']);
}else{
$username = NULL;
echo '<p><font color="red">You did not enter your desired username</font></p>';
}

//Check Full Name
if (!empty($_POST['fullname'])) {
$fullname = TRUE;
}else{
$fullname = NULL;
echo '<p><font color="red">You did not enter your fullname</font></p>';
}

//Check E-Mail Address
if (!empty($_POST['email'])) {
$email = TRUE;
}else{
$email = NULL;
echo '<p><font color="red">You did not enter your E-Mail Address</font></p>';
}

//Check Password
if (!empty($_POST['password1'])) {
$password1 = TRUE;
}else{
$password1 = NULL;
echo '<p><font color="red">You did not enter your First Password</font></p>';
}

//Check E-Mail Address
if (!empty($_POST['password2'])) {
$password2 = TRUE;
}else{
$password2 = NULL;
echo '<p><font color="red">You did not confirm your password</font></p>';
}

//Check Address Line 1
if (!empty($_POST['address1'])) {
$address1 = TRUE;
}else{
$address1 = NULL;
echo '<p><font color="red">You need to specify the first line of your address</font></p>';
}

//Check Address Line 2
if (!empty($_POST['address2'])) {
$address2 = TRUE;
}else{
$address2 = NULL;
echo '<p><font color="red">You need to specify the second line of your address</font></p>';
}

//Check City
if (!empty($_POST['city'])) {
$city = TRUE;
}else{
$city = NULL;
echo '<p><font color="red">You need to specify the town or city you live in</font></p>';
}

//Check Post Code
if (!empty($_POST['zip'])) {
$zip = TRUE;
}else{
$zip = NULL;
echo '<p><font color="red">You need to specify your post-code</font></p>';
}

// If everything is filled out print the message.
if($username && $password1) {

{ 
# THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE 
$sql = "INSERT INTO $db_table(username,fullname,email,password,level,address1,address2,city,zip) values ('$username','$fullname','$email','$password','$level','$address1','$address2','$city','$zip')"; 
($result = mysql_query($sql ,$db));

echo "Thank you, $username. You have now registered

With the details $fullname, $email, $password, $level, $address1, $address2, $city, $zip
Proceed to Login";

echo '';
}
?>

Link to comment
Share on other sites

Echo $sql right before mysql_query().

 

Just done that, I'm getting the following :

 

INSERT INTO users(username,fullname,email,password,level,address1,address2,city,zip) values ('test','1','1','test','entrepeneur','1','1','1','1')

 

I did have this PHP Script set on press of the Submit button and it seemed to enter the data no problem, But obviously I'd like it to validate the data inputted aswell

 

I did also try after each validation rule INSERT INTO $sql_table(username) value ($username);

But this also came up with a "1"

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.