shergold Posted July 5, 2009 Share Posted July 5, 2009 hey, i was wondering if anyone could help me with the following, <?php //connect to host and select database. include ('dbconnect.inc'); mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db ("test") or die(mysql_error()); //get POST data from form. $reg_username =$_POST[username]; $reg_password =md5($_POST[password]); $reg_email =$_POST[email]; $activation_code=uniqid(rand()); if (!isset($reg_username) || !isset($reg_password) || !isset($reg_email)) { echo "Please enter the required fields."; echo"</br><a href=\"javascript: history.go(-1)\">Back</a>"; } everytime i send data via the forum this php file returns the echo string i have set for the !isset if statement even when i enter data for all 3 fields. If anyone can point out my mistake i will be really gratefull. Thanks, Shergold. Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/ Share on other sites More sharing options...
seventheyejosh Posted July 5, 2009 Share Posted July 5, 2009 what does your form look like? also what if you echo the variables right before the if check? what is in them? echo "username - $reg_username hash_pass - $reg_password email - $reg_email"; exit(); Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869385 Share on other sites More sharing options...
shergold Posted July 5, 2009 Author Share Posted July 5, 2009 The form: <?php ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> </head> <meta name="generator" content= "HTML Tidy for Windows (vers 14 February 2006), see www.w3.org"> <title>Intranet Registration</title> </head> <body> <h3>Intranet Registration</h3> <form name="register" action="register.php" method="post" enctype="multipart/form-data" id="register"> Username: <input type="text" name="username" id="username" maxlength="20"><br> Password: <input type="password" name="password" id="password" maxlength= "30"></br> Email:<input type="text" name"email" id="email" maxlength = "60"></br> <input type="submit" value="submit"> </form> </body> </html> ill just echo them and get back to you. thanks, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869392 Share on other sites More sharing options...
seventheyejosh Posted July 5, 2009 Share Posted July 5, 2009 on the form, make sure that each of the inputs are on one line. like if i paste it in my editor there are breaks like u hit enter in the middle of each. also. name"email" should be name="email" Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869400 Share on other sites More sharing options...
shergold Posted July 5, 2009 Author Share Posted July 5, 2009 ah thank you i echo'ed and only the email wasn't showing. although now i have done this I'm getting another error, when i type a password im getting "The password is to long" string that i set. i used an if statement to check it. if (!isset($reg_username) || !isset($reg_password) || !isset($reg_email)) { echo "Please enter the required fields."; echo"</br><a href=\"javascript: history.go(-1)\">Back</a>"; } elseif( strlen($reg_username)>20 ) echo "$username is too long - <b>it must be 20 characters or under.</b>"; elseif( strlen($reg_password)>30 ) echo "your password is too long - <b>it must be 30 characters or under.</b>"; elseif( strlen($reg_email)>60 ) echo "your email address is too long - <b>it must be 60 characters or under.</b>"; else thanks allot for your help, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869407 Share on other sites More sharing options...
shergold Posted July 5, 2009 Author Share Posted July 5, 2009 ah its ok ive figured it out, since i used md5 to encrypt the password it changed to password into a 32 character string and i was only allowing 30 character strings. thanks, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869415 Share on other sites More sharing options...
Zane Posted July 5, 2009 Share Posted July 5, 2009 doing this $reg_username =$_POST[username]; will make an isset($reg_username) return true...always you need to test if it's empty() instead of isset. use isset on things in which if they weren't set you wouldn't have all the other variables either.....such as the submit button Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869418 Share on other sites More sharing options...
shergold Posted July 5, 2009 Author Share Posted July 5, 2009 ah ok sorry, i didnt realise, its the first time i used it. Thanks for your help, shergold. Quote Link to comment https://forums.phpfreaks.com/topic/164869-solved-isset-help/#findComment-869419 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.