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
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;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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