Jump to content

ashish11

New Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by ashish11

  1. PravinS... if replace the value of $score with the 1 instead of 0 then it only show value 1..not make increment according to correct answer..
  2. <?php include("connection.php"); $display = mysql_query("SELECT * FROM quiz ORDER BY qid"); if (!$_POST['submit']) { echo "<form method=post action=$PHP_SELF>"; echo "<table border=0>"; while ($row = mysql_fetch_array($display)) { $id = $row["qid"]; $question = $row["Question"]; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $answer = $row["answer"]; echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td><input type=radio name='q$id' value=\"$opt1\">$opt1 </td> <td><input type=radio name='q$id' value=\"$opt2\">$opt2 </td> <td><input type=radio name='q$id' value=\"$opt3\"></td>$opt3 </tr>"; } echo "</table>"; echo "<input type='submit' value='See how you did' name='submit'>"; echo "</form>"; } elseif ($_POST['submit']) { $score = 0; $total=mysql_num_rows($display); while ($result = mysql_fetch_array($display)) { $answer = $result['answer']; $q = "q$result[qid]"; $q = trim($q); if ($_POST[$q] == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; } ?>
  3. hello friend please help me in my code soon..i need urgent this code..if you have any query regarding code then post here I will tell you...
  4. I have manage the database.. database name is online.. table name is question.. column name is serialno,question.optiona,optionb,optionc,optiond,answer.. now I want that when click on answer than should not save in database ..only by comparison to save answer result should be shown... my code is this... <html> <head> <style> ul{border:0; margin:0; padding:0;} #pagination-digg li{ border:0; margin:0; padding:0; font-size:11px; list-style:none; margin-right:2px; } #pagination-digg a{ border:solid 1px #9aafe5; margin-right:2px; } #pagination-digg .previous-off, #pagination-digg .next-off { border:solid 1px #DEDEDE; color:#888888; display:block; float:left; font-weight:bold; margin-right:2px; padding:3px 4px; } #pagination-digg .next a, #pagination-digg .previous a { font-weight:bold; } #pagination-digg .active{ background:#2e6ab1; color:#FFFFFF; font-weight:bold; display:block; float:left; padding:4px 6px; } #pagination-digg .non-active{ background: #ff6633; color: #ff6633; font-weight:bold; display:block; float:left; padding:4px 6px; } #pagination-digg .non-white{ background: #FFFFFF; color: #ff6633; font-weight:bold; display:block; float:left; padding:4px 6px; } #pagination-digg .non-purple{ background: #800080; color: #ff6633; font-weight:bold; display:block; float:left; padding:4px 6px; } #pagination-digg a:link, #pagination-digg a:visited { color:#0e509e; display:block; float:left; padding:3px 6px; text-decoration:none; } #pagination-digg a:hover{ border:solid 1px #0e509e } </style> </head> <body> <?Php include('connection.php'); error_reporting(0); $id= $_GET['id']; if(($id)){ $result = mysql_query("SELECT serialno,question,optiona,optionb,optionc,optiond FROM question where serialno=".$id.""); } else{ $result = mysql_query("SELECT serialno,question,optiona,optionb,optionc,optiond FROM question where serialno=1"); } while($result=mysql_fetch_array($result)) { ?> <form name='question' method="post" > <?php echo $result['serialno'];?>.<?php echo $result['question']; ?> <br/> <input type="radio" name="a" value="<?php echo $result['optiona']; ?>"/><?php echo $result['optiona']; ?> <br/> <input type="radio" name="a" value="<?php echo $result['optionb']; ?>" /><?php echo $result['optionb']; ?> <br/> <input type="radio" name="a" value="<?php echo $result['optionc']; ?>" /><?php echo $result['optionc']; ?> <br/> <input type="radio" name="a" value="<?php echo $result['optiond']; ?>" /><?php echo $result['optiond']; ?> <?php } ?> <br /> <br /><br> remind me later <input type="checkbox" name="rememberMe" value="1" /> <input type="submit" name="next" style="width:50px;" value="Submit"/> <input type="submit" name="next" style="width:50px;" value="Next" onClick="window.location.href='online.php?id=<?php if (empty($id)){echo "2"; }else{echo $id+1;}?>';submit_form(); return false;" /> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $status= $_POST['a']; if(isset($_POST['rememberMe'])) { $status =3; } elseif(!empty($status)){ $status =1; //echo $status; }else{ $status=2; } $query ="SELECT serialno FROM status WHERE serialno = '".$id."'"; $testResult = mysql_query($query) or die('Error, query failed'); if(mysql_fetch_array($testResult) == NULL){ $sql = "INSERT INTO status ". "(serialno, status) ". "VALUES('$id','$status')"; $result = mysql_query($sql) or die('Error, query failed'); }else{ //update... $sql = "UPDATE status SET status='".$status."' WHERE serialno='".$id."'"; $result = mysql_query($sql) or die('Error, query failed'); } if(! $result ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; mysql_close($conn); $id=$id+1; header("Location: ?id=$id"); }else { echo ""; }; ?> <ul id="pagination-digg"> <?php $sql = mysql_query("SELECT * FROM status"); while($res=mysql_fetch_array($sql)){ $no = $res['serialno']; $status = $res['status']; ?> <li <?php if($status == 1){ echo "class='active'" ;}else if($status == 2){ echo "class='non-active'";}else if($status == 3){ echo "class='non-purple'";}else { echo "class='non-white'";}?>><a href="?id=<?php echo "$no";?>"><?php echo $no;?></a></li> <?php } ?> </ul> </body> </html> online.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.