Jump to content

Archived

This topic is now archived and is closed to further replies.

tawevolution

if + else statement help

Recommended Posts

ok, this is what I have so far:

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

$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:
[code]echo("$title");[/code]
But nothing ever comes up?!

Any help?
Thanks, Evo

[hr]
below is the full code:
[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");
?>
[/code]

Share this post


Link to post
Share on other sites
I dont get you logic but this is what i think you mean theo.

[code]
<?php

$1 = "1";

if($headof=1){

$title=="Head of ";

echo $title;

}else{

$title=="none";

echo $title;

}

?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=Orio link=topic=112772.msg457866#msg457866 date=1161860010]
or check if "$_POST['headof']" is set (isset($_POST['headof'])).
[/quote]
erm, how / where do i put that in the code?

Share this post


Link to post
Share on other sites
Instead of:
[code]if($headof=1)
{$title=="Head of ";}else{$title=="none";}[/code]

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


Orio :)

Share this post


Link to post
Share on other sites

×

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.