Jump to content

if else statement


pietbez
Go to solution Solved by mac_gyver,

Recommended Posts

pulling my hair out here, please help.

 

why am i getting a "maybe!" result no matter what my radio box selection is.

i know the variable gets passed to this php succesfully, i tested it with "echo $attend"

then i get the right results

 

but when i use this code, my result is always "maybe"

 

Please hepl

<?php

  $guest = $_REQUEST['guest'];
  $attend = $_REQUEST['attend'];
  $id = $_REQUEST['id'];
  
  include('include/connection.php');
	
  $query="UPDATE data SET guest = '$guest', attend = '$attend' WHERE id = '$id'";
  mysql_query($query) or die ('Error updating database');
  


  if ($attend == "yes")
  {
  echo "yes!";
  }
  else if ($attend == "no")
  {
  echo "no!";
  }
  else
  {
  echo "maybe!";
  }
  
?> 
Link to comment
Share on other sites

here is the form with the radio buttons

 

thanks

 <?php
 $id = $_REQUEST['id'];
 $guest = $_REQUEST['guest'];
 
 ?>
<html>
<head>
    <title>RSVP</title>
    <link rel='stylesheet' type='text/css' href='style.css' />
</head>

<body style="body">
    <ul id="nav">
     <li><a href="home.php?id=<?php echo $id; ?>&guest=<?php echo $guest; ?>">invitation</a></li>
     <li><a href="rsvp.php?id=<?php echo $id; ?>&guest=<?php echo $guest; ?>">rsvp</a></li>
     <li><a href="menu.php?id=<?php echo $id; ?>&guest=<?php echo $guest; ?>">menu</a></li>
     <li><a href="sleep.php?id=<?php echo $id; ?>&guest=<?php echo $guest; ?>">sleep</a></li>
     <li><a href="gifts.php?id=<?php echo $id; ?>&guest=<?php echo $guest; ?>">gifts</a></li>
    </ul>
 

    <div id="rsvp-wrap">
        <h2><?php echo $guest; ?></h2>
        <h2>Will you be joining us on our special day?</h2>
     <form method="post" action="rsvp_update.php">
      <table>
        <input type="hidden" name="guest" value="<?php echo $guest; ?>">
	<input type="hidden" name="id" value="<?php echo $id; ?>">
        
        <input type="radio" name="attend" value="Yes"/>- Yes yes yes! cant wait<br><br>
        <input type="radio" name="attend" value="Maybe"/>- Too early to say, gotta check my diary. but pencil me in<br><br>
        <input type="radio" name="attend" value="sorry"/>- Would love to be there, but wont be able to make it. Let me buy you a present to make up for it<br><br>
        <input type="radio" name="attend" value="No"/>- No. not gonna bother. never realy liked you guys that much anyway<br><br><br>
        <input type="Submit" value="Submit" />
      </table>
     </form>
    </div>
  </body>
</html>

Link to comment
Share on other sites

  • Solution

the values you are using in the form are Yes and No. those are not the same as the values in your comparisons, yes and no. the computer does exactly what your code says. the string 'Yes' is not equal to the string 'yes'.

 

there are very few cases in programming where letter-case doesn't matter, and those would be specifically documented.

Link to comment
Share on other sites

True and false boolean values are case-insensitive in PHP, for example.

 

<?php
$booltrue = TRUE;
$boolfalse = FALSE;
$citrue = true;
$cifalse = false;
$t = $booltrue === $citrue // $t now holds the value true
$f = $boolfalse === $cifalse // $f is also true now
?>
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.