Jump to content

[SOLVED] Arghhh!!!!


aim25

Recommended Posts

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. :P

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

<?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++;
} 
}
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.