tecmeister Posted February 6, 2008 Share Posted February 6, 2008 I Have created a register page. And i would like to know how you make the user enter all of the details or it will not register. meaning they cant leave one blank. How do i do that? Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/ Share on other sites More sharing options...
rhodesa Posted February 6, 2008 Share Posted February 6, 2008 Search the intar-web for Form Validation Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460052 Share on other sites More sharing options...
affordit Posted February 6, 2008 Share Posted February 6, 2008 $username=$_POST['username']; if (empty($username)) { echo"<a href='submit_registration.php'>All fields are required EXCEPT company.</a>"; exit(); // stop exec here } Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460065 Share on other sites More sharing options...
Grant Holmes Posted February 6, 2008 Share Posted February 6, 2008 I WISH I got royalties from these folks, but I don't. Sigh. Forms to go Especially if like me, you're a little weak on PHP Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460094 Share on other sites More sharing options...
phorcon3 Posted February 6, 2008 Share Posted February 6, 2008 <?php function check_fields() { $i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}} return $i; } if(isset($_POST['submit'])) { if(!empty(check_fields())) { echo 'All fields are required. Please try again.'; } else { mysql_query("INSERT INTO `table` () VALUES ()"); } } ?> that might do it Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460141 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 <?php function check_fields() { $i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}} return $i; } if(isset($_POST['submit'])) { if(!empty(check_fields())) { echo 'All fields are required. Please try again.'; } else { mysql_query("INSERT INTO `table` () VALUES ()"); } } ?> that might do it i have entered that script and i get this error: Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/sites/nurevolution.co.uk/public_html/register.php on line 37 I might of put it in the wrong place. This is part of my script: <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "***********"; $dbpass = "********"; mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); function check_fields() { $i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}} return $i; } if(isset($_POST['submit'])) { if(!empty(check_fields())) { echo 'All fields are required. Please try again.'; } else { mysql_query("INSERT INTO `table` () VALUES ()"); } } $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460307 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 if your only concern is blank and domt mind what ever they enter do this.......... $array = array ('name','lastname','email');//the value are your fields name in your form $empty = 0; foreach($array as $val){ if(empty($_POST[$val])){ $empty++;//emty } } if($emty == 0){ //do something }else{ //do something } try Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460314 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 I have entered that code in. But it didn't seem to work. This is what i had entered. $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $array = array ('name','lastname','email');//the value are your fields name in your form $empty = 0; foreach($array as $val){ if(empty($_POST[$val])){ $empty++;//emty } } if($emty == 0){ //do something }else{ //do something } Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460322 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $array = array ('name','email','username','password'); $empty = 0; foreach($array as $val){ if(empty($_POST[$val]) || !isset($_POST[$val])){ $empty++; } } if($emty == 0){ //do something here put here your insert query } else{ echo "wrong input"; } try Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460327 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 On the query part i dont know what to put. Im a total newbie. This is the script that im using on the register.php page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "**********r"; $dbpass = "**********"; mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); $$name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $array = array ('name','email','username','password'); $empty = 0; foreach($array as $val){ if(empty($_POST[$val]) || !isset($_POST[$val])){ $empty++; } } if($emty == 0){ //do something here put here your insert query } else{ echo "wrong input"; } $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } $query = "INSERT INTO users (name,email,username,password) VALUES('$name','$email','$username','$password')"; mysql_query($query)or die(mysql_error()); mysql_close(); $yoursite = 'www.nurevolution.co.uk'; $webmaster = 'Johnny McCaffery'; $youremail = 'support@nurevolution.co.uk'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $name, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution</a> Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "you have successfully Registered."; echo "Your information has been mailed to your email address."; ?> </body> </html> Once again thanks for all of you help Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460342 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "**********r"; $dbpass = "**********"; mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); $$name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $array = array ('name','email','username','password'); $empty = 0; foreach($array as $val){ if(empty($_POST[$val]) || !isset($_POST[$val])){ $empty++; } } if($emty == 0){ $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } else{ $query = "INSERT INTO users (name,email,username,password) VALUES('$name','$email','$username','$password')"; mysql_query($query)or die(mysql_error()); mysql_close(); $yoursite = 'www.nurevolution.co.uk'; $webmaster = 'Johnny McCaffery'; $youremail = 'support@nurevolution.co.uk'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $name, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution[/url] Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "you have successfully Registered."; echo "Your information has been mailed to your email address."; } } else{ echo "missing field"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460348 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 I have typed the code in and this is the error that i get: Parse error: syntax error, unexpected $end in /home/sites/nurevolution.co.uk/public_html/register.php on line 85 Line 85 is the last line </html> Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460372 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "**********r"; $dbpass = "**********"; mysql_connect ($dbhost,$dbuser,$dbpass)); mysql_select_db($dbname)or die(mysql_error()); $$name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $array = array ('name','email','username','password'); $empty = 0; foreach($array as $val){ if(empty($_POST[$val]) || !isset($_POST[$val])){ $empty++; } } if($empty == 0){ $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } else{ $query = "INSERT INTO users (name,email,username,password) VALUES('$name','$email','$username','$password')"; mysql_query($query)or die(mysql_error()); mysql_close(); $yoursite = 'www.nurevolution.co.uk'; $webmaster = 'Johnny McCaffery'; $youremail = 'support@nurevolution.co.uk'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $name, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution[/url] Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "you have successfully Registered."; echo "Your information has been mailed to your email address."; } } else{ echo "missing field"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460380 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 Sorry im still getting the same error. It must be something that i'm doing. Thanks for your help tho Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460386 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 I have tried this code that i had found. But i'm still getting the same error as i was with the other codes. I only get the error when i try to validate the form. This is the error that i'm getting: Parse error: syntax error, unexpected $end in /home/sites/nurevolution.co.uk/public_html/register.php on line 77. That is the end of the page. This is the code that im using. if($email == NULL || $username == NULL || $password == NULL || $name == NULL || $address1 == NULL || $address2 == NULL || city == NULL || $county == NULL || $postal == NULL || $country == NULL){ echo "You must complete all fields with *"; Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460673 Share on other sites More sharing options...
GameYin Posted February 7, 2008 Share Posted February 7, 2008 NONONONONONONO. <script type="text/javascript"> var red = 5; var blue = 3; var green = 3; var match = null; if ((red == blue) && (red == green)) { match = 'equal'; } else { purple = 'unequal'; } document.write(red + ' and ' + blue + ' are ' + match); </script> In this example the red must equal both the value in blue and the value in green for the if statement to evaluate as true. If either comparison evaluates as false then the entire if statement evaluates as false. Had we wanted to test if the value in red matched the value in blue or the value in green then we would have used the following if statement: if ((red == blue) || (red == green)) See what I mean? You can't use || if you want to test if all the values must be filled in. Hope this helps you!!! Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460738 Share on other sites More sharing options...
Wolphie Posted February 7, 2008 Share Posted February 7, 2008 Try something similar to <?php function validateForm() { $valid = false; foreach($_POST as $field) { if(empty($field)) { $valid = false; } else { $valid = true; } } if($valid) { echo 'Form submitted successfully.'; } else { echo 'Please fill in all fields.'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460798 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 I have tried all of the codes that people have told me to put. Everytime i enter their code i get this error: Parse error: syntax error, unexpected $end in /home/sites/nurevolution.co.uk/public_html/register.php on line 91 This is the register code that i using: <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "**********"; $dbpass = "*******"; mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $companyname = $_POST['companyname']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $city = $_POST['city']; $county = $_POST['county']; $postal = $_POST['postal']; $country = $_POST['country']; $phone = $_POST['phone']; $mobile = $_POST['mobile']; if(($email == NULL)&&($username == NULL)&&($password == NULL)&&($name == NULL)&&($address1 == NULL)&&($address2 == NULL)&&(city == NULL)&&($county == NULL)&&($postal == NULL)&&($country == NULL));{ echo "You must complete all fields with *"; include 'register.html'; exit(); $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); $query = "INSERT INTO users (name,email,username,password,companyname,address1,address2,city,county,postal,country,phone,mobile) VALUES('$name','$email','$username','$password','$companyname','$address1','$address2','$city','$county','$postal','$country','$phone','$mobile')"; mysql_query($query)or die(mysql_error()); mysql_close(); $yoursite = 'www.nurevolution.co.uk'; $webmaster = 'Johnny McCaffery'; $youremail = 'support@nurevolution.co.uk'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $name, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "you have successfully Registered."; echo "Your information has been mailed to your email address."; ?> Can someone please check it and tell me what is wrong. O and if i dont put the validate into the code it is working file. Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460861 Share on other sites More sharing options...
Wolphie Posted February 7, 2008 Share Posted February 7, 2008 Try this, you were missing an } <?PHP $dbhost = "localhost"; $dbname = "**********"; $dbuser = "**********"; $dbpass = "*******"; mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $companyname = $_POST['companyname']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $city = $_POST['city']; $county = $_POST['county']; $postal = $_POST['postal']; $country = $_POST['country']; $phone = $_POST['phone']; $mobile = $_POST['mobile']; if(($email == NULL)&&($username == NULL)&&($password == NULL)&&($name == NULL)&&($address1 == NULL)&&($address2 == NULL)&&(city == NULL)&&($county == NULL)&&($postal == NULL)&&($country == NULL));{ echo "You must complete all fields with *"; include 'register.html'; exit(); } $checkuser = mysql_query("SELECT username FROM users Where username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist >0){ echo "I'm sorry but the username that you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } $query = "INSERT INTO users (name,email,username,password,companyname,address1,address2,city,county,postal,country,phone,mobile) VALUES('$name','$email','$username','$password','$companyname','$address1','$address2','$city','$county','$postal','$country','$phone','$mobile')"; mysql_query($query)or die(mysql_error()); mysql_close(); $yoursite = 'www.nurevolution.co.uk'; $webmaster = 'Johnny McCaffery'; $youremail = 'support@nurevolution.co.uk'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $name, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "you have successfully Registered."; echo "Your information has been mailed to your email address."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460897 Share on other sites More sharing options...
tecmeister Posted February 7, 2008 Author Share Posted February 7, 2008 Thank you so much wolphie. It was all just beacuse of 1 }. Thanks again for everyones help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460981 Share on other sites More sharing options...
Wolphie Posted February 7, 2008 Share Posted February 7, 2008 Our pleasure Quote Link to comment https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460986 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.