Jump to content

Mutliple if statements


AJLX

Recommended Posts

If my SQL statement returns a result I want to change the background color of a cell. If the user is logged in I want to then show one of two buttons. either book, or cancel, depending on whether the cell is available or not. So far I have this:

 

$sql = "SELECT * FROM diary WHERE day = '$mon' AND studio_id ='mon11'";
$query = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($query) < 1)
{ 
$bgcolour= '#5DFC0A';
if(isSet($_SESSION['logged']))
{
$book = '<form action="../book.php" method="POST"><input type="hidden" name="day" value='.$mon.' type="text"/><input type="hidden" name="month" value='.$month.' type="text"/><input type="hidden" name="year" value='.$year.' type="text"/><input type="hidden" name="book_id" value="mon11" type="text"/><input type="submit" name="submit" value="Book!"></form>';
}} else {
$bgcolour= '#FF0000';
}
if(isSet($_SESSION['logged']))
{
$book = '<form action="../cancel.php" method="POST"><input type="hidden" name="day" value='.$mon.' type="text"/><input type="hidden" name="month" value='.$month.' type="text"/><input type="hidden" name="year" value='.$year.' type="text"/><input type="hidden" name="book_id" value="mon11" type="text"/><input type="submit" name="submit" value="Cancel!"></form>';
}
echo "<td rowspan='3' bgcolor=".$bgcolour.">";
if (isset($book)) 
{
    echo $book;
}

 

I want to use the $session(logged) variable to show the appropriate button, but I can't get it to work in the other if statement,

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/259818-mutliple-if-statements/
Share on other sites

Not sure if this would do what you want.

if(isset($_SESSION['logged']))
{
$book = '<form action="../cancel.php" method="POST"><input type="hidden" name="day" value='.$mon.' type="text"/><input type="hidden" name="month" value='.$month.' type="text"/><input type="hidden" name="year" value='.$year.' type="text"/><input type="hidden" name="book_id" value="mon11" type="text"/>';

$sql = "SELECT * FROM diary WHERE day = '$mon' AND studio_id ='mon11'";
$query = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($query) < 1){ 
$bgcolour="#5DFC0A";
$book .= '<input type="submit" name="submit" value="Book!"></form>';
}else{
$bgcolour="#FF0000";
$book .= '<input type="submit" name="submit" value="Cancel!"></form>';
}
}//if(isset($_SESSION['logged']))
echo "<td rowspan='3' bgcolor=\"$bgcolour\">";
if (isset($book)) 
{
    echo $book;
}
?>

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.