Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » if block not reading else NULL value RSS

if block not reading else NULL value

This thread was started by teknicalissue and has been viewed 831 times, and contains 5 replies, with the last reply made by Danny[MLWA].
Post Reply
1
View teknicalissue's reputation
Posted April 12 '09 at 12:44 PM
      Posts: 13
hello guys im writting a php block of code and for some reason its not reading the last else statement that says NULL

for ($i 0$i <= $count$i++)
{
    echo 
$i;
    echo 
$_POST['Race'] [$i] . "<br>" ;
    if (
$_POST['Race'] [$i] == "Black")
    {
        echo 
"you are Black";
    }else if (
$_POST['Race'] [$i] == "White")
    
    {
        echo 
"you are white";
    }else if (
$_POST['Race'] [$i] == "Hispanic")
    
    {
        echo 
"you are HIspanic";
    } else if (
$_POST['Race'] [$i] == "Asian")
    
    {
        echo 
"you are Asian";
    } 
    
    else if (
$_POST['Race'] == NULL){
        echo 
"you are an alien";
 }
    


any tips?

Advertisement Register for free to hide these ads and participate in discussions!

2
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted April 13 '09 at 08:35 AM
      Posts: 3,100
Is it "null" or "empty"? There is a difference.

I'm guessing it's empty.

And maybe you could use a drop-down form menu and not need to loop an array?

<select name="race">
<option value="White">White</option>
<option value="Black">Black</option>
<option value="Hispanic">Hispanic</option>
<option value="Asian">Asian</option>
<option value="Other">Other</option>
</select>

<?php
echo"
You are $_POST['race'].
";
>
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
mlseim is online now! Reply

3
View teknicalissue's reputation
Posted April 13 '09 at 11:48 AM
      Posts: 13
hm.. and do i just call upon the empty value by "" or EMPTY?. im doing this for the sake of learning. i know i could have used better types of the form to do this

4
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted April 15 '09 at 10:10 AM
      Posts: 3,100
This site has some tables and discussions about how PHP compares things:
http://au2.php.net/manual/en/types.comparisons.php

Probably answers it better than I can.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
mlseim is online now! Reply

5
View Hawaiiwebdesign's reputation
Posted June 12 '09 at 04:06 AM
      Posts: 5
Hi, teknicalissue! Did you find the answer you need on that site?
Last edited June 12 '09 at 04:11 AM by Wired ("removed fake sig"). Reply

6
32 points at 100%
Posted June 18 '09 at 04:13 AM
      Posts: 76
elseif (empty($_POST['Race']))

OR

elseif (!isset($_POST['Race']))

Both works
Lead Web Designer
MLW & Associates, LLP.
W3C Standards Complaint and SEO Friendly
Admin of Vraul

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Tutorial: How to Denormalize a Normalized Table Using SQL smoseley Coding Articles & Tutorials 4 July 6 '09 01:59 AM
mysql help needed Demon Templates MySQL and MaxDB 1 February 11 '09 01:28 PM
Creating conditional foreign key relationships in MySQL TheGardener MySQL and MaxDB 6 October 13 '07 03:05 PM
JS menu alignment in IE robbieM Javascript, AJAX, and JSON 0 January 28 '05 09:33 AM