如果语句忽略elseif

I have this if statement. It is part of a php script that is run when a button is clicked to determine the page it is forwarded to. I have a table that is updated when an admin changes the page and this all works fine. For some reason however this is always forwarding to scriptone. Even though for instance scriptthree is definately selected. Any suggestions please?

$sql = "SELECT scriptName FROM selectedscript WHERE scriptSelected = '1'";

if($sql = "ScriptOne") {
    header('Location: scriptone.php');
}
elseif ($sql = "ScriptTwo") {
    header('Location: scripttwo.php');
}
elseif ($sql = "ScriptThree") {
    header('Location: scriptthree.php');
}
else {
    echo "Error";
}

Thank you

I have tried double and triple equal signs however that leads to the Error message being displayed :(

You'll need to perform the sql query and fetch some values before using them in your if statements.

Something like this:

$sql = "SELECT scriptName FROM selectedscript WHERE scriptSelected = '1'";
$q=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($q);

switch ($row['scriptName']) {
  case 'ScriptOne':
    header('Location: scriptone.php');
    break;
  case 'ScriptTwo':
    header('Location: scripttwo.php');
    break;
  case 'ScriptThree':
    header('Location: scriptthree.php');
    break;
  default:
    echo "Error";
}

Also, consider using PDO instead of mysql_* statements as they are depreciated.

if($sql == "ScriptOne") {
         ^

not

if($sql = "ScriptOne") {

= is assignment, == is comparison

You need to use double or triple equal signs

if($sql == "ScriptOne") {

= is assignment. == is equality. === is strict equality. You want one of the latter as the first typically results in a true value.

if ($sql == "ScriptOne") {
    header('Location: scriptone.php');
}