hannap Posted July 10, 2012 Share Posted July 10, 2012 Hello! I have a problem to compare a value given by a subject as an input ($_POST["sava"]) and an integer value taken from a MySQL table mysql_connect("","root"); mysql_select_db("chat"); $coran = mysql_query("select * from pretest_tasks"); $cansw = mysql_fetch_assoc($coran); $cana=$cansw["answ1a"]; In which form is the $_POST input and how can I compare it to the integer value with if-else structure? This far I have tried the string comparison and the direct == comparison, but it always goes into the else-part saving the given answer as 'incorrect'. The piece of PHP code can be seen below: $compa=strcmp($_POST["sava"],$cana); if($_POST["sava"]==$cana) { /* OR if($compa==0) { */ $corr='correct'; mysql_query("insert workspace1 ($savecor, $savea, $saveb) values ('" . $corr . "','" . $_POST["sava"] . "', '" . $_POST["savb"] . "')"); } else { $corr='incorrect'; mysql_query("insert workspace1 ($savecor, $savea, $saveb) values ('" . $corr . "','" . $_POST["sava"] . "', '" . $_POST["savb"] . "')"); } How should I change the format of $_POST or integer to make them comparable? Thank you! Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 10, 2012 Share Posted July 10, 2012 Please post all code in the forum's code tags. Before any of the processing, add print_r($_POST); And see if the values are what you expect. You should also probably print_r($cansw); and make sure it has the values you expect. You are not checking to see if your query was actually successful, so that could be failing. 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.