I am writing a quiz website.
What should happen is:
- A page has a question on it and four buttons or a textbox.
- When you click a button, it calls itself with
the answer number in the address
like:
?q=[question number]&a=[answer].
- If the question uses a textbox it POSTs the answer.
- This code should then detect that something has been sent to it and write that to a database.
- The user id is stored in a cookie.
- There is also a key column in the database. the idea is that it stores all answers a user has submitted over time and users can change their answers.
<?PHP mysql_connect("------", "------", "------") or die(); mysql_select_db("------") or die(); $q=$_GET['q']; if(isset($_GET['a'])){ $a=$_GET['a']; } else { $a=$_POST['longanswer']; } if(isset($a)){ $u=$_COOKIE['id']; if($qust['atype']==1){ mysql_query("INSERT INTO answers (
userid
,answer
,qid
) VALUES ($u, $a, $q);"); } else { mysql_query("INSERT INTO answers (userid
,answer
,qid
) VALUES ($u, '$a', $q);"); } } ?>
I don't think it should matter, but later on on the code, it queries the database with the SELECT command.
When i run this code, it seems to enter 2 or 3 entries to the database. The trend seems to be that when i run the code it enters the previous answer, followed by the new answer.
Any help would be greatly appreciated. Thanks,
Logan