Rother2005 Posted January 2, 2007 Share Posted January 2, 2007 when the user sumbits the form it is inputtin the data into the data as just blanks :S, i has worked before i input the //checks if user has input text section[code]<?phpinclude('connect1.inc');?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Booze Cruise Reg</title></head><body><?php if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username"></p><p align="center">Password: <input type="text" name="password"></p><p align="center">Firsname: <input type="text" name="firstname"></p><p align="center">Surname: <input type="text" name="surname"></p><p align="center">Address 1: <input type="text" name="address1"></p><p align="center">Address 2: <input type="text" name="address2"></p><p align="center">Town: <input type="text" name="town"></p><p align="center">County: <input type="text" name="county"></p><p align="center">Postcode: <input type="text" name="postcode"></p><p align="center">Tel No: <input type="text" name="telno"></p><p align="center">Mobile: <input type="text" name="mobile"></p><p align="center">Email: <input type="text" name="email"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} //27else{//checks if user has input textif ($username=$_POST['username'] == "") { die ("No Username Input");}if ($password=$_POST['password'] == "") { die ("No Password Input");}if ($firstname=$_POST['firstname'] == ""){ die ("No Fristname Input");}if ($surname=$_POST['surname'] == "") { die ("No Surname Input");}if ($address1=$_POST['address1'] == "") { die ("No Address Input");}if ($town=$_POST['town'] == "") { die ("No Town Input");}if ($county=$_POST['county'] == "") { die ("No County Input");}if ($postcode=$_POST['postcode'] == "") { die ("No Postcode Input");}if ($email=$_POST['email'] == "") { die ("No Email Input");}//encrypts password server side into md5 32bytes$password = stripslashes($password);$password = md5($password);$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";mysql_query($sql) or die(mysql_error());//50echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/ Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 You cant validate a variable and assign it at once. This makes no sense...[code=php:0]if ($username=$_POST['username'] == "") { die ("No Username Input");}[/code]Try...[code=php:0]if ($_POST['username'] == "") { die("No Username Input");} else { $username = $_POST['username'];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151463 Share on other sites More sharing options...
Rother2005 Posted January 2, 2007 Author Share Posted January 2, 2007 again it still in putting blanks :(would i work if i put [code]if ($username=$_POST['username'] == "") { die ("No Username Input");}else INSERT INTO member(Username) vaules ('$username')"; [/code]im just tryin to validate weather or not a user has input a value Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151479 Share on other sites More sharing options...
wildteen88 Posted January 2, 2007 Share Posted January 2, 2007 thorpe just said you cant do this:[code]if ($username=$_POST['username'] == "") {[/code]Use the isset function then check the value of the variable like so:[code=php:0]if(isset($_POST['username']) && !empty($_POST['username'])){ // valid}else{ // not valid}[/code]Also when validating form data do not kill the script for every check. Log the errors in an array then check if there any errors after you;ve validated all the fields. If there are errors log display them along with the form. If there are no errors then continue on. Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151482 Share on other sites More sharing options...
Rother2005 Posted January 3, 2007 Author Share Posted January 3, 2007 thanks wildteen88 [code]if(isset($_POST['username']) && !empty($_POST['username'])){ // valid}else{ // not valid}[/code]will i have to do this for each input and do i need to put anything in the //vaild and //not vaild parts?? Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151818 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 [quote]will i have to do this for each input and do i need to put anything in the //vaild and //not vaild parts??[/quote]Yes and Yes. Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151863 Share on other sites More sharing options...
Rother2005 Posted January 3, 2007 Author Share Posted January 3, 2007 im just a little confused on what to place inside the vaild and non vaild partswill it be echo non vaild for non vaild :Dbut how will i get it to contine to check the next input? will it be like this:[code]if(isset($_POST['username']) && !empty($_POST['username'])){ // valid if(isset($_POST['password']) && !empty($_POST['password'])) { // valid } else { echo non vaild }}else{ echo non vaild}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-151879 Share on other sites More sharing options...
Rother2005 Posted January 4, 2007 Author Share Posted January 4, 2007 can anyone help Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-153134 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 Please I’m really lost with getting this working any help is well appreciated[code]<?phpinclude('connect1.inc');?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Booze Cruise Reg</title></head><body><?php if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username"></p><p align="center">Password: <input type="text" name="password"></p><p align="center">Firsname: <input type="text" name="firstname"></p><p align="center">Surname: <input type="text" name="surname"></p><p align="center">Address 1: <input type="text" name="address1"></p><p align="center">Address 2: <input type="text" name="address2"></p><p align="center">Town: <input type="text" name="town"></p><p align="center">County: <input type="text" name="county"></p><p align="center">Postcode: <input type="text" name="postcode"></p><p align="center">Tel No: <input type="text" name="telno"></p><p align="center">Mobile: <input type="text" name="mobile"></p><p align="center">Email: <input type="text" name="email"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} //27else{//checks if user has input textif ($username=$_POST['username'] == "") { die ("No Username Input");}else { $username = $_POST['username'];}if ($password=$_POST['password'] == "") { die ("No Password Input");}else { $username = $_POST['password'];}if ($firstname=$_POST['firstname'] == ""){ die ("No Fristname Input");}else { $username = $_POST['firstname'];}if ($surname=$_POST['surname'] == "") { die ("No Surname Input");}else { $username = $_POST['surname'];}if ($address1=$_POST['address1'] == "") { die ("No Address Input");}else { $username = $_POST['address1'];}if ($town=$_POST['town'] == "") { die ("No Town Input");}else { $username = $_POST['town'];}if ($county=$_POST['county'] == "") { die ("No County Input");}else { $username = $_POST['county'];}if ($postcode=$_POST['postcode'] == "") { die ("No Postcode Input");}else { $username = $_POST['postcode'];}if ($email=$_POST['email'] == "") { die ("No Email Input");}else { $username = $_POST['email'];}//encrypts password server side into md5 32bytes$password = stripslashes($password);$password = md5($password);$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";mysql_query($sql) or die(mysql_error());//50echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154384 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 foreach($_POST AS $key=>$value){ //This will loop through each posted var.} Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154387 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 i dnt really understand what your getting at lol i think its something to do with this part[code]if ($username=$_POST['username'] == "") { die ("No Username Input");}else { $username = $_POST['username'];}[/code]but i dnt know what to change, add, delete, loop :S Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154394 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 Did you read what anyone posted? Several times you've been told that isn't valid code. Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154395 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 because i am stupid il ask a stupid question, is there code to check if the user has input data once they submit?because from the one im using like u say its invalid so any point in the right direction is greatcheers in advance Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154410 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 Read the other posts here. Specifically this one: http://www.phpfreaks.com/forums/index.php/topic,120692.msg495350.html#msg495350Don't call yourself stupid, just take the time to actually think about it and READ the answers you're given. Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154416 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 [code]if(isset($_POST['username']) && !empty($_POST['username'])){ // valid}else{ // not valid}[/code]right from this then, what do i need to put in the vaild part?? $username = $_POST['username'];?the non vaild could i put [code] die ("No Username Input"); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154427 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 Sure... Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154430 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 rite kinda sorted....ive got some fields that i dont need a input for e.g. tel no, mobile 2nd line of address now as a test to see if the form was working the codes not inputting the data into the database is there a piece of code that will need to be used that will allow it to be blank / no entrycheers Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154452 Share on other sites More sharing options...
Rother2005 Posted January 6, 2007 Author Share Posted January 6, 2007 help anyone?? ??? Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154541 Share on other sites More sharing options...
Rother2005 Posted January 7, 2007 Author Share Posted January 7, 2007 hi ive got the checks to work but for some reason my address2, telno and mobile fields will not input data into the databse now ive checked the spelling (in the code and database) and it seems fine can anyone spot owt' wrong?[code]<?phpinclude('connect1.inc');?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Booze Cruise Reg</title></head><body><?php if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p><form name="form1" method="POST" action=""><p align="center">Username: <input type="text" name="username" maxlength="10"></p><p align="center">Password: <input type="password" name="password" maxlength="10"></p><p align="center">Firsname: <input type="text" name="firstname" maxlength="20"></p><p align="center">Surname: <input type="text" name="surname" maxlength="20"></p><p align="center">Address 1: <input type="text" name="address1" maxlength="20"></p><p align="center">Address 2: <input type="text" name="address2" maxlength="20"></p><p align="center">Town: <input type="text" name="town" maxlength="20"></p><p align="center">County: <input type="text" name="county" maxlength="20"></p><p align="center">Postcode: <input type="text" name="postcode" maxlength="7"></p><p align="center">Tel No: <input type="text" name="telno" maxlength="12"></p><p align="center">Mobile: <input type="text" name="mobile" maxlength="12"></p><p align="center">Email: <input type="text" name="email" maxlength="30"></p><p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';} //27else{//checks if user has input textif(isset($_POST['username']) && !empty($_POST['username'])){ // valid $username = $_POST['username'];}else{ // not valid die ("No Username Input");}if(isset($_POST['password']) && !empty($_POST['password'])){ // valid $password = $_POST['password'];}else{ // not valid die ("No Password Input");}if(isset($_POST['firstname']) && !empty($_POST['firstname'])){ // valid $firstname = $_POST['firstname'];}else{ // not valid die ("No Firstname Input");}if(isset($_POST['surname']) && !empty($_POST['surname'])){ // valid $surname = $_POST['surname'];}else{ // not valid die ("No Surname Input");}if(isset($_POST['address1']) && !empty($_POST['address1'])){ // valid $address1 = $_POST['address1'];}else{ // not valid die ("No Address Input");}if(isset($_POST['town']) && !empty($_POST['town'])){ // valid $town = $_POST['town'];}else{ // not valid die ("No Town Input");}if(isset($_POST['county']) && !empty($_POST['county'])){ // valid $county = $_POST['county'];}else{ // not valid die ("No County Input");}if(isset($_POST['postcode']) && !empty($_POST['postcode'])){ // valid $postcode = $_POST['postcode'];}else{ // not valid die ("No Postcode Input");}if(isset($_POST['telno']) && !empty($_POST['telno'])){ // valid $email = $_POST['telno'];}else{ // not valid die ("No Tel No Input");}if(isset($_POST['mobile']) && !empty($_POST['mobile'])){ // valid $email = $_POST['mobile'];}else{ // not valid die ("No Mobile No Input");}if(isset($_POST['email']) && !empty($_POST['email'])){ // valid $email = $_POST['email'];}else{ // not valid die ("No Email Input");}if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)) { echo "The email you entered is not valid. Please try again. <br/>"; exit(); }//encrypts password server side into md5 32bytes$password = stripslashes($password);$password = md5($password);$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";mysql_query($sql) or die(mysql_error());//50echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32574-reg-form-is-inserting-blank-info-in-database/#findComment-154563 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.