Search code examples
phpformsauto-incrementincrement

making site id increment by 1


Hey guys im trying to make a quiz and currently I have ran into an issue, I have made it increment but not send the data, so I need to fix it but don't really know how to, I need the users to be able to select an option the data get sent to the next page but the page must also increase in increment. this is what I have got

<form name="form2" method="post" >
<select name="answer">
<option value=$myrow['A']><?php echo $myrow['A']?></option>
<option value=$myrow['B']><?php echo $myrow['B']?></option>
<option value=$myrow['C']><?php echo $myrow['C']?></option>
<option value=$myrow['D']><?php echo $myrow['D']?></option>

 <input type="submit" name="submit" value="Continue" onclick = "window.location.href = 'testttts.php?id=<?php echo $count?>'"

any help would be great thank you!!


Solution

  • Is this what you mean?

    <?php
    
    if(isset($_POST['i'])) {
        $i = $_POST['i'];
    } else {
        $i = 0;
    }
    
    echo "increment: " . $i;
    $i++;
    ?>
    
    <form name="form2" method="post" >
    <select name="answer">
    <option value=$myrow['A']><?php echo $myrow['A']?></option>
    <option value=$myrow['B']><?php echo $myrow['B']?></option>
    <option value=$myrow['C']><?php echo $myrow['C']?></option>
    <option value=$myrow['D']><?php echo $myrow['D']?></option>
    </select>
    <input type="hidden" name="i" value="<?php echo $i; ?>" />
    
    <input type="submit" name="submit" value="Continue" />