Hello. I have been trying to create a script that, if a correct answer is posted to the page, points are added to a user's profile. Also, it should add a number to a field, and does a strstr on the feild, so that the user cannot just re-post the answer and gain more points. I know that this code adds points properly, but the rest I am stuck with. Could you check out the syntax for me? And help me to see what the problem is. <?php if (isset($_POST['answer'])){ if ($_POST['answer'] == 'answer to question'){ $con = mysql_connect("XXXXXXXXXXXXXXXXX"); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("b13_980789_db", $con); $username = $_SESSION['username']; $isitdone = mysql_query("SELECT * FROM basic WHERE username = '$username'"); if((strstr($isitdone, '1')) === FALSE){ mysql_query("UPDATE `b13_980789_db`.`users` SET `points` = points+3 WHERE `users`.`username` = '$username'; UPDATE `b13_980789_db`.`users` SET `basic` = basic + '1' WHERE `users`.`username` = '$username'"); echo "Congratulations."; } else{ } mysql_close($con); } } ?> Code (markup):
I have a seesion start on the page, yes. And no, I have not fixed this yet. I think perhaps that it is a problem with the fact that $isitdone is a MySQL query, not a string? Thanks for your help, but I'm still not sure.
since i don't know what your table layout the should be a column / inidividual table which record the questions that have been answered corectly. query that table / column, compare the result of the query with the posted answer then log it up if it is different. you are on the right direction, isitdone is a mysql query. you should compare to the query result and not the query.