Jump to content


Photo

if + else statement help


  • Please log in to reply
5 replies to this topic

#1 tawevolution

tawevolution
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 October 2006 - 10:43 AM

ok, this is what I have so far:

if($headof=1)
{$title=="Head of ";}else{$title=="none";}

$headof is taken from an imput checkbox (i know that works) where if it it checked then the value is 1, but I dont know why the if statement doesnt work.

At the bottom of the form I then have:
echo("$title");
But nothing ever comes up?!

Any help?
Thanks, Evo

 
below is the full code:
<?php
$self = $_SERVER['PHP_SELF'];
$real = $_POST['real'];
$tag = $_POST['tag'];
$dept = $_POST['dept'];
$lang = $_POST['lang'];
$headof = $_POST['headof'];
?>
<p><form action="<?php echo( $self ); ?>" method="post" enctype="multipart/form-data">
  <table width="500" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
      <td><strong>Member Language:</strong></td>
      <td><select name="lang">
	    <option value="err">Choose a Language</option>
        <option value="en">English</option>
        <option value="fr">French</option>
        <option value="de">German</option>
		<option value="us">American</option>
        </select>
        </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
	<tr>
      <td><strong>Real Name:</strong></td>
      <td><input name="real" type="text" size="30" /></td>
    </tr>
	<tr>
      <td><strong>TLS Name:</strong></td>
      <td><input name="tag" type="text" size="30" /></td>
    </tr>
	<tr>
      <td><strong>Department:</strong></td>
      <td><select name="dept">
        <option value="err">Choose a Department</option>
        <option value="Management">Management</option>
        <option value="Programming">Programming</option>
        <option value="3D Artists">3D Artists</option>
        <option value="2D Artists">2D Artists</option>
        <option value="Website Development">Website Development</option>
        <option value="Sound Development">Sound Development</option>
        <option value="Translation">Translation</option>
        <option value="Beta Testing">Beta Testing</option>
        <option value="Other">Other</option>
      </select>
      </td>
	</tr>
	<tr>
      <td><strong>Head of Department?</strong></td>
      <td><input type="checkbox" name="headof" value="1" /></td>
    </tr>
	<tr>
      <td>&nbsp;</td>
      <td><input name="submit" type="submit" value="Submit" />
          <input type="reset" name="Reset" value="Reset" />
      </td>
    </tr>
</table>
</form></p>

<?php
$1 = "1";

if($headof=1)
{$title=="Head of ";}else{$title=="none";}

#now echo the contents of the form
echo("$lang, $real, $tag, $dept, $title");
?>


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 October 2006 - 10:50 AM

I dont get you logic but this is what i think you mean theo.

<?php

$1 = "1";

if($headof=1){

$title=="Head of ";

echo $title;

}else{

$title=="none";

echo $title;

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 10:53 AM

For check boxes, the test is not "if($headof=1)".
To check if a checkbox was ticked, you either check if the value of $headof is "on" ($headof=="on"), or check if "$_POST['headof']" is set (isset($_POST['headof'])).

The second option is the better one.

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 tawevolution

tawevolution
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 October 2006 - 10:59 AM

or check if "$_POST['headof']" is set (isset($_POST['headof'])).

erm, how / where do i put that in the code?

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 11:18 AM

Instead of:
if($headof=1)
{$title=="Head of ";}else{$title=="none";}

You should put:
if(isset($_POST['headof']))
{$title=="Head of ";}else{$title=="none";}


Orio :)
Think you're smarty?

(Gone until 20 to November)

#6 tawevolution

tawevolution
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 October 2006 - 11:21 AM

ok thanks guys

evo




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users