stublackett Posted January 30, 2008 Share Posted January 30, 2008 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 ''; } ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted January 30, 2008 Share Posted January 30, 2008 Echo $sql right before mysql_query(). Quote Link to comment Share on other sites More sharing options...
kts Posted January 30, 2008 Share Posted January 30, 2008 Also try utilizing the or die(mysql_error()) ex. $result = mysql_query($sql ,$db) or die(mysql_error())); Quote Link to comment Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 Either your sql querry is full of 1's or your default for the fields is 1 and you are not entering any data. Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 3, 2008 Author Share Posted February 3, 2008 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" Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2008 Share Posted February 3, 2008 You code is specifically setting all the variables in the query to true (which has a value of 1) if the POST variable is not empty. Here is just one of them - $address2 = TRUE; Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 3, 2008 Author Share Posted February 3, 2008 So thats changing the values to "1" obviously being TRUE; Changing that to FALSE would then change that to "0" So whats the best way to then input that data? Many Thanks Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 3, 2008 Author Share Posted February 3, 2008 Apologies, I've managed to sort that out Solved by adding $email = ($_POST['email']); etc etc Data now inserted into table is valid Many Thanks! 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.