rick001 Posted March 6, 2012 Share Posted March 6, 2012 For some reason the !isset() function doesnt seem to work i cant find out why hope you guys will be able to help Here is the html code for the form where the user enters the data <div id="contact_form"> <h2>On Site SEO Signup Form</h2> <form method="post" name="contact" action="http://www.techbreeze.in/freeseo.php"> <label for="uname">Name:</label> <input name="uname" type="text" class="required input_field" id="uname" /> <div class="cleaner h10"></div> <label for="email">Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" /> <div class="cleaner h10"></div> <label for="website">Website:</label> <input type="text" class="required input_field" id="website" name="website"/> <div class="cleaner h10"></div> <label for="ftp">Your FTP Login URL:</label> <input type="text" class="required input_field" id="url" name="url" /> <div class="cleaner h10"></div> <label for="username">Your FTP Username:</label> <input type="text" class="required input_field" id="user" name="user" /> <div class="cleaner h10"></div> <label for="password">Your FTP Password:</label> <input type="password" class="required input_field" id="pass" name="pass"/> <div class="cleaner h10"></div> <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" /> <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" /> </form> </div> And here is the code for the .php file where the !isset() function is used <?php // validation expected data exists if( !isset($_POST['uname'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Name" field empty!'); } if( !isset($_POST['pass'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Password" field empty!'); } if( !isset($_POST['email'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Email" field empty!'); } if( !isset($_POST['website'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Website" field empty!'); } if( !isset($_POST['url'])) { die ('We are sorry, but all the fields are necessary you cant leave the "FTP URL" field empty!'); } if( !isset($_POST['user'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Username" field empty!'); Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/ Share on other sites More sharing options...
darkfreaks Posted March 6, 2012 Share Posted March 6, 2012 your have to many IF statement that is your problem. if you have too many they will return false no matter what. try to keep it like if($variable) {} else { some code } Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324378 Share on other sites More sharing options...
rick001 Posted March 6, 2012 Author Share Posted March 6, 2012 ok i changed that part to <?php // validation expected data exists if( (!isset($_POST['uname']))|| ( !isset($_POST['pass'])) || (!isset($_POST['email'])) || ( !isset($_POST['website'])) || ( !isset($_POST['url'])) || (!isset($_POST['user']))) { die ('We are sorry, but all the fields are necessary. Please fill them up carefully!!'); } But it still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324382 Share on other sites More sharing options...
darkfreaks Posted March 6, 2012 Share Posted March 6, 2012 you are not getting it even using one statement but a shiton of variables does not changing the fact your using TOO MANY. change your logic. if (variable) { pass } else {fail} always check for pass and fail not one or the other. Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324387 Share on other sites More sharing options...
trq Posted March 6, 2012 Share Posted March 6, 2012 your have to many IF statement that is your problem. if you have too many they will return false no matter what. Sorry, but you do not know what your talking about. Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324407 Share on other sites More sharing options...
JonnoTheDev Posted March 6, 2012 Share Posted March 6, 2012 isset() is not the best method to use. It is used to test if a variable is in existence withing the scope of the script. It is not used to test whether a variable contains a value. i.e <?php $x = ''; if(isset($x)) print "x is set"; ?> I have cleaned up your code, so replace all those isset() tests at the top with the following: <?php $required_fields = array('uname','pass','email','website','url','user'); $error = false; foreach($required_fields as $field) { if(!strlen(trim($_POST[$field])) && !$_CLEAN[$field]) { $error = true; } } if($error) { die ('We are sorry, but all the fields are necessary. Please fill them up carefully!!'); } ?> What you should do is record the fields that are missing the input and print them out so the user knows what to fill in as opposed to just exiting the script with a simple die(). You could do this with: <?php $required_fields = array('uname' => 'username', 'pass' => 'password', 'email' => 'email', 'website' => 'website','url' => 'url', 'user' => 'user'); $errors = array(); foreach($required_fields as $field => $name) { if(!strlen(trim($_POST[$field])) && !$_CLEAN[$field]) { $errors[] = $name.' is a required field'; } } if(count($errors)) { /* display errors */ print implode('<br />', $errors); } else { /* process input */ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324420 Share on other sites More sharing options...
l0gic Posted March 7, 2012 Share Posted March 7, 2012 Save your server some time and validate your form with JavaScript? Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324721 Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2012 Share Posted March 7, 2012 JavaScript is NOT validation. Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324724 Share on other sites More sharing options...
scootstah Posted March 7, 2012 Share Posted March 7, 2012 your have to many IF statement that is your problem. if you have too many they will return false no matter what. Huh? Quote Link to comment https://forums.phpfreaks.com/topic/258365-isset-function-not-working/#findComment-1324726 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.