orbitter Posted March 2, 2008 Share Posted March 2, 2008 if anyone can help, this scrpt is not working, could you tell me wat is wrong with it please? this script shows a question and then lets a user answer it. then a messages comes up saying whether the question was right or wrong. also could someone help me with, how to make anothe table and script in order to store the answer that was selected? any help would be appreciated, thank you the table i created was: CREATE TABLE one ( id int(1) NOT NULL auto_increment, question varchar(65) NOT NULL default '', answerone varchar(65) NOT NULL default '', answertwo varchar(65) NOT NULL default '', answerthree varchar(65) NOT NULL default '', answerfour varchar(65) NOT NULL default '', correctanswer varchar(65) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; and the script is: <? //YOUR DB CONNECTION HERE mysql_connect("localhost", "root", "123456") or die(mysql_error()); mysql_select_db("orbit") or die(mysql_error()); $getquestion= mysql_query("SELECT * FROM one"); $num= mysql_num_rows($getquestion); if ($num == "0"){ echo "There are currently no questions"; }else{ $the= mysql_fetch_object($getquestions); //GET FIRST OR ONLY QUESTION FROM DB ?> <form method="post" action=""> Question: <?= ucfirst($the->question); ?> <input type="radio" name="answer" value="<?= $the->answerone ?>"> <?= ucfirst($the->answerone); ?> <input type="radio" name="answer" value="<?= $the->answertwo ?>"> <?= ucfirst($the->answertwo); ?> <input type="radio" name="answer" value="<?= $the->answerthree ?>"> <?= ucfirst($the->answerthree); ?> <input type="radio" name="answer" value="<?= $the->answerfour ?>"> <?= ucfirst($the->answerfour); ?> <input type="hidden" name="id" value="<?= $the->id ?>"> <input type="submit" name="submit" value="Check"> </form> <? if (strip_tags($_POST['answer']) && strip_tags($_POST['submit'])){ $answer= $_POST['answer']; $i= $_POST['id']; //NO NEED FOR SECURITY BECAUSE THE DATA FROM THE INPUT STUFF ARE NOT CHANGEABLE $select= mysql_fetch_object(mysql_query("SELECT * FROM one WHERE id='$i'")); if ($answer != $select->correctanswer){ echo "Your answer ($answer) was incorrect!"; }else{ echo "Your answer '$answer' was correct!"; }} ?> <? } ?> 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.