aim25 Posted July 11, 2007 Share Posted July 11, 2007 I don't know why this doesn't work. This is part of the form <select name="gender"> <option value="male">Male</option> <option value="female">Female</option> </select> And this is the php. <?php function gender() { global $gender, $poster, $error; if (isset($poster)) { if (!ctype_alpha($gender)) { echo "<li>error-1!</li>"; $error++; } elseif ($gender !== "male" || $gender !== "female") { echo "<li>error-2!</li>"; $error++; } } } ?> The problem is that when ever i run this it always returns error-2, i dont know why becuase the select is either equal too "male" or "female". Please help, its killing me. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 <?php $gender = $_GET['gender']; function gender() { global $gender, $poster, $error; if (isset($poster)) { if (!ctype_alpha($gender)) { echo "<li>error-1!</li>"; $error++; } elseif ($gender !== "male" || $gender !== "female") { echo "<li>error-2!</li>"; $error++; } } } ?> Try that you are assuming register_globals is on which chances are it is not, and if it is it shouldnt be due to security risks. Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 11, 2007 Author Share Posted July 11, 2007 i have $gender = $_POST['gender']; Quote Link to comment Share on other sites More sharing options...
trq Posted July 11, 2007 Share Posted July 11, 2007 [code=php:0]} elseif ($gender != "male" || $gender != "female") { Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 11, 2007 Author Share Posted July 11, 2007 Already tried that Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 <?php function gender() { global $poster, $error; $gender = $_POST['gender']; // set it here if (isset($poster)) { if (!ctype_alpha($gender)) { echo "<li>error-1!</li>"; $error++; } elseif ($gender !== "male" || $gender !== "female") { echo "<li>error-2!</li>"; $error++; } } } ?> I would do that or pass it as a parameter to the function: <?php $gender = $_POST['gender']; echo $gender . " gender<br />"; // make sure it is being populated right echo gender($gender); // run the function function gender($gender) { global $poster, $error; if (isset($poster)) { if (!ctype_alpha($gender)) { echo "<li>error-1!</li>"; $error++; } elseif ($gender !== "male" || $gender !== "female") { echo "<li>error-2!</li>"; $error++; } } } ?> Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 11, 2007 Author Share Posted July 11, 2007 O, i see for some reason the data isn't being passed on, thanks, now on to my next problem :'( Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 11, 2007 Author Share Posted July 11, 2007 Nope it seems as though it was passed through, but it still doesnt work. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 Does gender print out? Have you tried printing out gender in the if statements? Have you tried just != instead of !== ? Given the code above, it should work unless foul play is coming about like for some reason the data is not being posted? Post more code is the gist of it. Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 11, 2007 Author Share Posted July 11, 2007 When i use my code and add the print $gender it prints out error-2male(or female), but when i use yours i get the same problem. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 Post your actual code that you are using this function for. 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.