0

If I have a form as in the below script:

<html>
<?php
session_start();

 $con=mysqli_connect("localhost","root","","QSTNS");
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

   $dsply=$_SESSION['q_indx'][$_SESSION['cindx']] ; 
  //echo $dsply ;
  $qstn = mysqli_query($con,"SELECT * FROM qstns where qid = '". $dsply ."'");

  $qstn = $qstn->fetch_array(MYSQLI_ASSOC);

   //echo $qstn['qname'] . "<br>";
   //echo $qstn['opta'] ."<br>";
   //echo $qstn['optb']."<br>";
   //echo $qstn['optc']."<br>";
   //echo $qstn['optd']."<br>";

    mysqli_close($con);
       ?>

    <body>

 <?php echo $qstn['qname'] ."<br>"; ?>
 <form action="prcs_ansr.php" method="post">
  <input type="radio" name="rply" value="A" /><?php echo $qstn['opta'] ; ?><br />
 <input type="radio" name="rply" value="B" /><?php echo $qstn['optb']; ?> <br />
 <input type="radio" name="rply" value="C" /><?php echo $qstn['optc']; ?><br />
 <input type="radio" name="rply" value="D" /><?php echo $qstn['optd']; ?> <br/>
 <input type="submit" value="previous">
 <input type="submit" value="next">
  </form>


 </body>
  </html>

I have two buttons in a single form and I want to process each one separately and for that I used isset() but it didn't work. The code for the next page is:

           <?php
          session_start() ;

          $con=mysqli_connect("localhost","root","","QSTNS");
         if (mysqli_connect_errno()) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }

         if (isset($_POST['previous'])) {
         if($_SESSION['cindx']>0)
         $_SESSION['cindx']-=1;
         }
         if(isset($_POST['next']))
           {
         $res=mysqli_query($con, 'SELECT COUNT(*) FROM qstns');
         $row = mysqli_fetch_array($res);
         //echo $row[0];

         if($_SESSION['cindx']<$row[0]-1)
         $_SESSION['cindx']+=1;
           }
        //echo 'here';
        header('Location: quiz_start.php');

    mysqli_close($con); 
     ?>

Can anyone help?

Edited by pritaeas: Moved.

2
Contributors
1
Reply
9
Views
2 Years
Discussion Span
Last Post by AleMonteiro
0

Try something like this:

<input type="hidden" name="buttonaction" value="D" />
 <input type="submit" onclick="javascript: document.form.buttonaction.value=this.value;" value="previous">
 <input type="submit" onclick="javascript: document.form.buttonaction.value=this.value;" value="next">

 <?php
    $action = $_POST["buttonaction"];
 ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.