PHP - Quiz Scripting Help
Ok this is kind of a logical help which I need. I am writing a quiz script and I need to send and receive data from database on a timeout basis and I also want that when time finishes (of quiz) user must be moved to some other page. I basically need timeout based function if there are any and real time retrieval and storage of data. Thanks a lot
Similar TutorialsHi, I'm working on a design for a new website of mine, but I'm kind of stuck on how to fit in the php aspect of it. There's going to be a lot of different pages and different things you're able to do on each page. I guess I'm trying to figure out how to take my design for the website and break it up into a template system. I don't know anything about using templates though. The last time I tried to make a template I just winged it and it turned out really bad with a lot of confusing code slapped together with html all around it. Right now all I have is a single page made (front page) and I want to use this as my base template. Could anyone explain to me the proper way to go about this, or perhaps link me to a tutorial covering this. Thanks, http://www.lastcraft.com/browser_documentation.php can someone post back an example of where this is working? <?php require_once('simpletest/browser.php'); $browser = &new SimpleBrowser(); $browser->get('http://php.net/'); $browser->click('reporting bugs'); $browser->click('statistics'); $page = $browser->click('PHP 5 bugs only'); preg_match('/status=Open.*?by=Any.*?(\d+)<\/a>/', $page, $matches); print $matches[1]; ?> I am trying to generate data similar to a running balance for a checkbook. My approach (correct me if there is a better method) is to get the balance from the previous record ID and then add/subtract the new value and create a new total balance. However, I am not havig succes with MAX(id) or last_insert_id -- is one preferable over the other?? if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ $sql = "SELECT MAX(id) FROM persons"; echo "<br /<br />"; echo $sql; Please assist. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=342389.0 Hi I need to test for XSS attack and aim is to break my own site. I am using strip_tags to strip all the HTML and tags. Is there any way for successful XSS attack even if strip_tags is used. This is my first attemp at a log in system for a website. Everything seems to work fine until the "successful" IF function near the end. All I get it an output of "?>" instead of a redirect to the file "login_success.php". Any help would be GREATLY appreciated!! Tom <?php // Connect to server and select databse. mysql_connect("localhost", "scripts3_public", "sfj123!")or die("cannot connect"); mysql_select_db("scripts3_sfj")or die("cannot select DB"); // username and password sent from form $fusername=$_POST['fusername']; $fpassword=$_POST['fpassword']; // To protect MySQL injection (more detail about MySQL injection) $fusername = stripslashes($fusername); $fpassword = stripslashes($fpassword); $fusername = mysql_real_escape_string($fusername); $fpassword = mysql_real_escape_string($fpassword); $sql="SELECT * FROM `users` WHERE `User name` = '$fusername' AND `Password` = '$fpassword'"; $result=mysql_query($sql); if(!mysql_num_rows($result)) {echo "No results returned.";} // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $fusername and $fpassword, table row must be 1 row if($count==1){ // Register $fusername, $fpassword and redirect to file "login_success.php" session_register("fusername"); session_register("fpassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Hello,
I designed (not coded) a finance application for windows phone 8.1 and one of the features that would be ideal is to copy your login steps in order to access your bank account automatically. Yes this does not sound safe or sane. How do I convince app users to use it?
Anyway, I want this access. My rationale is that, the login information would be stored locally and if my phone was hacked then what's the loss in my login steps being hacked... they would probably be encrypted anyway but...
The goal is to be able to open up a clone browser (eg. within the app) and then every step that you take, enter url, login credentials, security questions, pages accessed... the clone browser remembers and then later on as part of the app's function, it would automatically update your balances. I mean I suppose you could come up with the formulas, cash advance fees, interest rates, etc... but at the same time this doesn't seem to be a fixed thing... eg. hard to keep track and get the exact cent amount... or maybe I'm just bad at math
Some things in mind bitmapping, key strokes, string search, number search...
Anyway scripting came to mind, not sure if php or python but
Any thoughts?
Hello. I try to write a simple multiple choice quiz. I have my questions and answers in a xml file and I read the file into an array. My main problems is how I'll connect the various sessions where the different questions appear in order to keep the score and sum it up in the end. Also, how do I check if the selected answer is correct or not? Assuming that the correct answers are in an array in php code, can I use javascript to check the answers? Any help? Thanks. can anyone please tell me how can I make a quiz in php which displays random questions one at a time
Hey guys,
I'm making php quiz, but got some problems with results getting - they are all wrong. Here is the db table for it.
CREATE TABLE IF NOT EXISTS `quiz` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `question` text COLLATE utf8_unicode_ci NOT NULL, `answer1` text COLLATE utf8_unicode_ci NOT NULL, `answer2` text COLLATE utf8_unicode_ci NOT NULL, `answer3` text COLLATE utf8_unicode_ci NOT NULL, `correctanswer` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `pollid` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=34 ;And script itself. $questionNumber = 1; $query = sql_query("SELECT * FROM quiz ORDER BY RAND() LIMIT $limit"); while ($result = mysqli_fetch_array($query)) { ?> <div class="padding"> <p> <?php echo "<b><h4>" . $questionNumber . ") " . $result['question'] . "</h4><br></b>"; ?> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer1']; ?> <br> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer2']; ?> <br> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer3']; ?> <br> </p> <hr> </div> <?php $questionNumber +=1; } $correctAnswers = 0; $wrongAnswers = 0; $questions = ''; $idList = join (',', array_map('intval', array_keys($_POST['answer']))); $sql = "SELECT id, question, answer1, answer2, answer3, correctanswer FROM quiz WHERE id IN ($idList)"; $res = sql_query($sql) ; $qno = 1; while (list($id, $q, $a, $b, $c, $correct) = mysqli_fetch_row($res)) { if ($correct == $_POST['answer'][$id]) { $correctAnswers +=1; } else { $wrongAnswers +=1; } } echo $correctAnswer; echo $wrongAnswers; ?>Help me guys! Hi all, Can anyone offer assistance with the following: I am trying to obtain a score from a users radio button selection on a simple quiz. i am not able to obtain the results.... Hello everyone, I have a datatbase containing fields id, question, answer, and type. The questions are in true/false format, multiple choice and fill in the blank(text). At the moment, I am only trying to get the true and false questions to work. My code is as follows Code: [Select] <?php $connection = mysql_connect("localhost","root","root") or die("couldn't connect"); $select = mysql_select_db("login") or die ("cannot select database!"); $query = mysql_query("SELECT * FROM questions"); $numrows = mysql_num_rows($query); if ($numrows!=0) { //code to login while($row = mysql_fetch_assoc($query)) { $dbquestion = $row['question']; $dbanswer = $row['answer']; $dbtype = $row['type']; $dbid = $row['id']; $correctanswer = explode('|',"$dbanswer"); switch($dbtype){ case "mchoice": echo"<br/>"; echo $dbquestion; echo"<br/>"; break; case "boolean": echo"<br/>"; echo $dbquestion; echo"<br/>"; echo $correctanswer[0]; //display radio buttons ?> <form name="boolean" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> True <input name="question" type="radio" value= "True" /> False <input name="question" type="radio" value= "False" /> <input name="id" input type="hidden" value="<?php $dbid ?>" /> <input type="submit" name="submit" id="submit" value="Submit" /> <?php echo "The answer submitted was "; echo $_POST['question']; ?> <?php break; case "text": echo"<br/>"; echo $dbquestion; echo"<br/>"; //display text box break; } } } ?> The problem I'm having is that this creates a submit button for each question. When choosing true or false for the answer and pressing submit, the answer is selected for every question. I need the code to look at what the user has entered, check the answer against correctanswer[0]. I'm really in a bit of a hole here and if anyone can help me it would be greatly appreciated. Many thanks in advance James i want online quiz in php mysql Hi people. I'm building a quiz with one correct answer out of possible 4. My problem is that after I choose a random answer (which is the correct one) I have problems with choosing random 3 wrong answers which are not the same as answer 1 (they all come from the same table). My first mysql query gives me back 1 row my second mysql query gives me back 15 row (there were 16 - 1 which is the correct one). How can take only 3 rows out of that second query and output them into variables that I can later echo into a form? Can you help me understand this problem or can you propose an alternative method to deal with this? Here are my two queries: Code: [Select] // Fetch random answer (correct) $query = "SELECT * FROM psychofarm_brand WHERE `id`=".$randomNumber; $result = mysql_query($query); $row = mysql_fetch_array($result); // Fetch wrong answer $query2 = "SELECT * FROM psychofarm_gen WHERE `id`!=".$randomNumber; $result2 = mysql_query($query2); $row2 = mysql_fetch_array($result2); I hope this is clear. Thanks I've made a code here.. It can create a quiz. It consist of a question and a 4 choices.. But my problem here is. when i inserted only 2 values for the choices, there would still be 4 radio button(Choices). Can someone help me. i want my code to be like : When user inputs 4 values. there would be 4 choices, but when user insert 2 values, there would be 2 values.. Here's my code for the form Code: [Select] <form name="formupload" method="post" action="setdate.php"> <div id="apDiv10"><input type="image" src="images/setdate.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="valdeactiveass.php"> <div id="apDiv8"><input type="image" src="images/deacass.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="valactiveass.php"> <div id="apDiv7"><input type="image" src="images/activeass.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="quiz_preview.php"> <div id="apDiv3"><input type="image" src="images/preview.png" name="Image9" width="170" height="35" border="0" ></div> </form> <form name="form2" method="post" action="delques.php"> <div id="apDiv9"><input type="image" src="images/delques.png" name="Image8" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="validatequiz.php"> <input type="text" style="position:absolute; top:160px; left:101px; width: 576px; height: 31px; font-size:10px;" name="question" id="question" /> <input type="text" style="position:absolute; top:244px; left:109px; width: 567px; height: 19px; font-size:10px;" name="c1" id="c1" /> <input type="text" style="position:absolute; top:297px; left:108px; width: 567px; height: 19px; font-size:10px;" name="c2" id="c2" /> <input type="text" style="position:absolute; top:350px; left:109px; width: 567px; height: 19px; font-size:10px;" name="c3" id="c3" /><input type="text" style="position:absolute; top:396px; left:110px; width: 567px; height: 19px; font-size:10px;" name="c4" id="c4" /> <select style="position:absolute; top:463px; left:309px; width: 80px; height: 23px; font-size:10px;" name="answer" id="answer"> <option value="Select">Select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select><div id="apDiv2"><input type="image" src="images/submit.png" name="Image8" width="170" height="35" border="0" ></div> </form> And this of the quiz maker.. Code: [Select] <?php if (isset($_POST['sent'])) { for ($i=0;$i<count($questions);$i++) { if ($_POST['q2'.$i]=="w") { $score++; } else { } } $percent = number_format(($score/count($questions))*100,2,".",","); echo("<br>".$score." out of ".count($questions)." (".$percent."% right)<br>\n"); } else { echo("<form action=\"#\" method=\"post\">\n"); echo("<input type=\"hidden\" name=\"sent\">\n"); for ($i=0;$i<count($questions);$i++) { echo("<b>".$questions[$i][0]."</b><br><br>\n"); if ($questions[$i][5]==1) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][1]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][1]."<br>\n"); } if ($questions[$i][5]==2) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][2]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][2]."<br>\n"); } if ($questions[$i][5]==3) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][3]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][3]."<br>\n"); } if ($questions[$i][5]==4) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][4]."<br><br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][4]."<br><br>\n"); } } echo("<input type=\"submit\" value=\"Submit Exam\"></form>"); } ?> Hello, I am trying to build a quiz with PHP and MySQL. I have successfully managed to build the database and display the questions from the database. I have also managed to get the radio button to individually map to each question (rather than seeing all questions with one possible answer). What I have been unable to do (for some days now) is to match the correct radio button with the answer (all say incorrect at the moment even if you answer correctly.) Any help would be greatly appreciated. Code below questions.php Code: [Select] <?php require_once('connectvars1.php'); //Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); $query = "SELECT * FROM questions"; $result = mysqli_query($dbc, $query); // if records are present if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); if (mysqli_num_rows($result) > 0) { // print answer list as check boxes while ($row = mysqli_fetch_array($result)) { $id = $row['autokey']; $quest = $row['q_text']; $option1 = $row['op1']; $option2 = $row['op2']; $option3 = $row['op3']; $option4 = $row['op4']; $answer= $row['answer']; echo "$quest"; ?> <br /> <input type= radio name= <?php echo "$id" ?> <value="A"/>A. <?php echo "$option1" ?><br /> <input type= radio name= <?php echo "$id" ?> <value="B"/>B. <?php echo "$option2" ?><br /> <input type= radio name= <?php echo "$id" ?> <value="C"/>C. <?php echo "$option3" ?><br /> <input type= radio name= <?php echo "$id" ?> <value="D"/>D. <?php echo "$option4" ?><br /> <br /> <?PHP } ?> <br /> <div align="center"><input type="submit" name="btn_submit" value="Submit Answers" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php } echo '</form>'; } mysqli_close($dbc); ?> score.php Code: [Select] <?php // Check answers if((isset($_POST['$id'])) && ($_POST['$id'] == "$answer")){ echo 'Your answer was correct for q1!'; }else{ echo 'Your answer was incorrect for q1.'; } ?> <br /> <?php if((isset($_POST['$id'])) && ($_POST['$id'] == "$answer")){ echo 'Your answer was correct for q2!'; }else{ echo 'Your answer was incorrect for q2.'; } ?> Could anyone help me please. I am trying to create a quiz in (quiz.php) which is works fine, but when I am trying to correct the quiz in another page (result.php) I had an error. I think the problem with posted answers and I couldn't solve it.
This is my code in (quiz.php):
<form method="post" action="result.php"> <?php session_start(); $questionNumber = 1; $query = mysql_query("SELECT * FROM Question WHERE TID = 'TEST' order by RAND()"); while ($result = mysql_fetch_array($query)) { ?> <?php echo $questionNumber . ") " . $result['Question'] . "<br>"; ?> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="A"> <?php echo $result['A']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="B"> <?php echo $result['B']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="C"> <?php echo $result['C']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="D"> <?php echo $result['D']; ?> <br> <?php $questionNumber +=1; } ?> <input type="submit" name="checkQuiz" value="Check Quiz" onclick="location.href='result.php'" /> </form>And This is my code in (result.php): <?php if(isset($_POST['checkQuiz'])) { $correctAnswers = 0; $wrongAnswers = 0; $idList = join (',', array_map('intval', array_keys($_POST['answer']))); $sql = "SELECT QID, Answers FROM correct WHERE QID IN ($idList)"; while (list($QID, $correct) = mysql_fetch_row($res)) { if ($correct == $_POST['answer'][$QID]) { $correctAnswers +=1; } else { $wrongAnswers +=1; } } } ?> // in the body <?php $numberOfQs = $correctAnswers + $wrongAnswers; $score = round(($correctAnswers / $numberOfQs) * 100); ?> Correct Answers: <?php echo $correctAnswers; ?> <br> Wrong Answers: <?php echo $wrongAnswers; ?> <br> Sco <?php echo $score; ?> Hey all! I am new to these forums, but this seems like a really good place for information. I am a beginner in PHP coding, so I don't have that much experience with how to do quite simple tasks. I have a job to fulfill and I have to create a personality quiz, which basically means a user answers about eight questions with three choices and then he will be dubbed as one of six different personalities. I've tired doing this, believe me, but I just don't get it to work. Are there any websites, downloads, or words of advice you guys could give me? And no, I will not be using one of those quiz generators online; it should be made from raw code. Thank you so much! |