pietbez Posted June 22, 2013 Share Posted June 22, 2013 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!"; } ?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 22, 2013 Share Posted June 22, 2013 you probably have some white-space or non-printing character as part of the form field value. care to post the code making the form? Quote Link to comment Share on other sites More sharing options...
pietbez Posted June 22, 2013 Author Share Posted June 22, 2013 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> Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted June 22, 2013 Solution Share Posted June 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
pietbez Posted June 22, 2013 Author Share Posted June 22, 2013 sorry for that. that was a stupid mistake. cant believe i didnt pick that up. sometimes when you stare at the code to long you start missing things. thanks for that. Quote Link to comment Share on other sites More sharing options...
Irate Posted June 23, 2013 Share Posted June 23, 2013 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 ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.