-5

Below is my code. The posted statement is working & bringing variables through.

However, the if statement $table="1" is overwriting the $table variable with the value 1... so the check is always true.

Can anyone help me fix this?

Thank you!

<?php
    print_r($_POST);


    $table = $_POST['origintable'];
    $database = $_POST['origindatabase'];

    if ($table = "1") { 
        echo "<br> &nbsp;&nbsp;&nbsp;&nbsp; Database name: <b>$database</b> Table name:<b>$table</b>.";
    }
    else {
        echo "Have a good night!";
    }
?>
Subhrajyoti Das
  • 2,685
  • 3
  • 21
  • 36

2 Answers2

3

you need to use == operator because = is an assignment operator and == is comparison operator or you can use === if you want to check same type with comparison example given below

if ($table == "1") { 

example

if (1 == "1") {
    // it will return true
}
if (1 === "1") {
     // it will return false
}
Rahul
  • 1,617
  • 1
  • 9
  • 18
1

try this, compare == operator

if ($table == "1") { 
    echo "<br> &nbsp;&nbsp;&nbsp;&nbsp; Database name: <b>$database</b> Table name:<b>$table</b>.";
}
else {
    echo "Have a good night!";
}
Rp9
  • 1,955
  • 2
  • 23
  • 31