Jump to content

Code not executing beyond a point


Andreycon

Recommended Posts

I am playing around with php but the script doesnt execute to the last point and with no error... 

 

What i am trying to do is checking the input of the user and comparing it what is in db and then applying conditions. So i have 2 files. update.php and home.php. 

home.php is my html form page and i included 'update.php' in it

In my update.php, i have these codes


 

<?php

error_reporting(E_ALL);


include_once('database.php');

if(isset($_POST['submit']))

{

$q = $_GET['q'];

$next = $q + 1;

if($q == 26)
{
echo '<h2>You have Completed the Exam.Congrats!!</h2>';


}
elseif($q <= 25){
    
$sql = "SELECT * FROM Students WHERE Email=?";
$stmt = $conn->prepare($sql); 
$stmt->bind_param('s', $_SESSION['login']);
$stmt->execute();
$result = $stmt->get_result(); $row = $result->fetch_assoc();

$Mark = $row['Mark'];


$Correct = $Mark + 1;


$Fail = $Mark + 0;

  
$sqlb = "SELECT * FROM Answers WHERE qid = ?";
$stmtb = $conn->prepare($sqlb); 
$stmtb->bind_param('s', $q);
$stmtb->execute();
$resultb = $stmtb->get_result();

$rowb = $resultb->fetch_assoc();

$Answer = $rowb['Answer'];

$Pick = $_POST['ans'];

if($Pick ==  $Answer)

{
  
  
    
  $sqld = "UPDATE Students SET Mark=? WHERE Email = ?";
$stmtd = $conn->prepare($sqld); 
$stmtd->bind_param('ss', $Correct,$_SESSION['login']);
$stmtd->execute();
$resultd = $stmtd->get_result();  


   echo "correct" ;
}

}
else

{
    
    echo 'Ate';
echo "<script type='text/javascript'>document.location.href='home.php?q='.$next.';</script>";
}

}//post submit

?>


The else statement doesnt run. so it keeps reloading the same page.   

  Also i want to ask why i keep getting the value of 2 for my $Correct variable stored on the database into column Mark for a single correct question instead of 1. What could be wrong?

Lastly, i dont want the script to run if the browser is edited by the user by changing the value of $q from the browser, because i am using get method, is there a way to do that.

Please be nice with your comments. Thanks in advance.!!!

Link to comment
Share on other sites

n applying conditions. So i have 2 files. update.php and home.php. 



home.php is my html form page and i included 'update.php' in it



In my update.php, i have these codes




 


<?php error_reporting(E_ALL); include_once('database.php'); if(isset($_POST['submit'])) { $q = $_GET['q']; $next = $q + 1; if($q == 26) { echo '<h2>You have Completed the Exam.Congrats!!</h2>'; } elseif($q <= 25){      $sql = "SELECT * FROM Students WHERE Email=?"; $stmt = $conn->prepare($sql);  $stmt->bind_param('s', $_SESSION['login']); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $Mark = $row['Mark']; $Correct = $Mark + 1; $Fail = $Mark + 0;    $sqlb = "SELECT * FROM Answers WHERE qid = ?"; $stmtb = $conn->prepare($sqlb);  $stmtb->bind_param('s', $q); $stmtb->execute(); $resultb = $stmtb->get_result(); $rowb = $resultb->fetch_assoc(); $Answer = $rowb['Answer']; $Pick = $_POST['ans']; if($Pick ==  $Answer) {              $sqld = "UPDATE Students SET Mark=? WHERE Email = ?"; $stmtd = $conn->prepare($sqld);  $stmtd->bind_param('ss', $Correct,$_SESSION['login']); $stmtd->execute(); $resultd = $stmtd->get_result();      echo "correct" ; } } else {          echo 'Ate'; echo "<script type='text/javascript'>document.location.href='home.php?q='.$next.';</script>"; } }//post submit ?>

Is rhe code clearer now?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.