Jump to content

if + else statement help


tawevolution

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]
Link to comment
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.
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.