Jump to content

if..elseif.. else not working


tjverge

Recommended Posts

The below code should take you to a different page depending on what you choice in the drop down, but all the results only take you to the first on even when you put a different option in the drop down, any ideas?

<?php
ob_start();
session_start();
$pagerank=1; 
if ($rank < $pagerank){
header('Location:main.php?id=lowrank.php');
}
else{
?>
<form action="main.php?id=search.php" method="post">
<table width="725" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="228">Name: <input name="name" type="text" /></td>
    <td width="490"><select name="type">
    <option>All</option>
    <option>Alliance</option>
    <option>Corporation</option>
    <option>Pilot Name</option>
    <option>Ship Name</option>
    <option>Ship Type</option>
    <option>System Name</option>
    <option>System Type</option>
    </select></td>
  </tr>
  <tr>
    <td></td>
    <td><input name="Submit" type="Submit" /></td>
  </tr>
</table>
</form>
<?php
if (isset($_POST['Submit'])) {
$name = $_POST['name'];
$type = $_POST['type'];

if ($type = "System Name" OR "System Type") {
header('Location:main.php?id=searchsystem.php');
exit;
}

Elseif ($type = "All")
{
header('Location:main.php?id=searchall.php');
exit;
}
Else
{
header('Location:main.php?id=searchpilot.php');

}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/223739-ifelseif-else-not-working/
Share on other sites

All of your <option> tags are missing their value= attributes.

 

So I added the attributes

<select name="type">
    <option value="All">All</option>
    <option value="Alliance">Alliance</option>
    <option vaule="Corporation">Corporation</option>
    <option vaule="Pilot Name">Pilot Name</option>
    <option vaule="Ship Name">Ship Name</option>
    <option vaule="Ship Type">Ship Type</option>
    <option value="System Name">System Name</option>
    <option value="System Type">System Type</option>
    </select>

but it still has the same result

$type = "System Name" is assignment. $type == "System Name" is comparison.

Updated still only going to the searchsystem.php

if ($type == "System Name" OR "System Type") {
header('Location:main.php?id=searchsystem.php');
exit;
}

Elseif ($type == "All")
{
header('Location:main.php?id=searchall.php');
exit;
}
Else
{
header('Location:main.php?id=searchpilot.php');

}

Archived

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

×
×
  • 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.