Is it possible for $variable to take different values at the point of the INSERT query? If my statement is false, how can I achieve this.
Thank you.
if(isset($_GET['id'])) {
$variable = "Foo" ;
}
elseif (!isset($_GET['id'])) {
$variable = "Bar" ;
}
$sql = mysql_query("INSERT INTO tbl
tbl_id, variable
VALUES('$id', '$variable'");
One variable can hold only one value at once and in your code it’s valid. If
idis available it’ll haveFoo, otherwise it’ll haveBarand alternatively you can write it in one line as follows:Then you can use your
$variablevariable later in your script. It’ll contain at least one valueFooorBar.