Change page from Next button with id

how to link submit button to another page in html
javascript click button by id
how to redirect from one page to another in html on button click
button id html
how to make a button link to another page in html
button html to next page
html button
button onclick

I'm doing a program where I have several exercises with their id (e.g. Id = 1, 2, 3 ...) What I would like to do is that once the user is in an exercise, he can press the Next button and take him to the next exercise, for example id + 1.

Below I show what I've done. Can you help me?

This is my modified question, now it works:


// Start the session
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";

$conn = new mysqli($servername, $username, $password, $dbname);
/*echo*/ $id=$_GET['id']; // Current question
$sql = "SELECT * FROM exercises where exercise_id='$id'";
$result = $conn->query($sql); /*Check connection*/

$question_ids = [];
$result2 = doSearch($conn, 'exercise_id');
while($row = $result2->fetch_assoc()) {
    array_push($question_ids,  $row["exercise_id"]);
$order = $_GET['order'];
$next_question_id = -1;
$next_question_order = $order + 1;
if (count($question_ids) >= $next_question_order) {
    $next_question_id = $question_ids[$order];


<div id="centered_B" class="header">

    $row = $result->fetch_assoc();


    <p><?php echo $row["exercise_id"] . ". " . $row["text"]?></p>
    <img width="603" height="auto" src="<?php echo $row["image_path"]?>"><br/><br/>

    <form action='' method='post'>
        <input type="radio" name="choice" value= "1" /><img src="<?php echo $row["image_path_A"] ?>"/><br>
        <input type="radio" name="choice" value= "2" /><img src="<?php echo $row["image_path_B"] ?>"><br>
        <input type="radio" name="choice" value= "3" /><img src="<?php echo $row["image_path_C"] ?>"><br>

    <br><br><br><!--- Select difficulty --->

    <p2>Select difficulty level:</p2>

    <form action='' method='post'>
        <select name="choose" id="choose">>
        <option value="1" <?php if($row["difficulty"]=="1") { echo "selected"; } ?> >1</option>
        <option value="2" <?php if($row["difficulty"]=="2") { echo "selected"; } ?> >2</option>
        <option value="3" <?php if($row["difficulty"]=="3") { echo "selected"; } ?> >3</option>
        <option value="4" <?php if($row["difficulty"]=="4") { echo "selected"; } ?> >4</option>
        <option value="5" <?php if($row["difficulty"]=="5") { echo "selected"; } ?> >5</option>


        <input class="buttonSubmit" type="submit" name="submit" value="Submit">
        if ($next_question_id >= 0) {
            <a href="?id=<?php echo $next_question_id; ?>&order=<?php echo $next_question_order; ?>" class="buttonNext" >Next Question</a>


</div><!--- end of centered_B div --->


if (isset($_POST['submit'])) {
    $user_id = $_SESSION['user_id'];
    $user_check_query = "SELECT * FROM users WHERE id='$user_id'";
    if(isset($_POST['choice'], $_POST['choose'])){
//      */$user_id = $_SESSION['user_id'];*/
            $query = "INSERT INTO answers (exercise_id_fk, student_id, difficulty_student, choice_answer) VALUES ('$id','$user_id', '$difficulty', '$choice_answer')";


How to create an HTML button that acts like a link?, How do I move one HTML page to another button? Button mButton = (Button) findViewById (; Note: In order to look for an ID of a view inside the layout file we need to call this method provided by Android called (findViewById), then we pass the ID of the view by first starting with (R) as resource, ID and then the actual ID of the view. Great now we have added a button in activity

Maybe this can help you:

var i=$_GET['id']){;

function getNext()
    var = var + 1; //increase var by one
return var;

<button class="buttonNext" onclick="getNext" >Next Question</button>

HTML Forms, What I would like to do is that once the user is in an exercise, he can press the Next button and take him to the next exercise, for example id + 1. Where is previous/next page button with keyboard control? Started the game with keyborad and can not seem to move pages for upgrading skills and blueprints. Anyone who plays with keyboard, help me out?

Uhm, I don't know where to start here... Ok, for first your code is horrible - regarding in style, security and everything - sorry ;)

But to help with your problem: Don't access the next id directly but go by

SELECT * FROM exercises  WHERE exercise_id > $currentId ORDER BY exercise_id ASC LIMIT 0,2

This will help if you want to delete an exercise at some point, so have a gap like 1,2,4 (3 was deleted). You can also create a position field to sort the order of the question manually, but I guess that's too advanced for first.

However: On start you check if there's a $_GET['id'] param and set this to $currentId. Best by $currentId = (int)$_GET['id'] to prevent a serious injection. If no GET param is there, set $currentId = 0 (first call then). Then you run the query to get your exercise - it will be in the first row of the result.

On HTML side you just assign the exercise_id from the database result to the link which leads on the next exercise (so no JavaScript is required).

To test, if there's a next question at all check if a second row exists in the result (that's why LIMIT 0,2 instead of 0,1) to decide if to show the "next exercise button".

Change page from next button with id, I've got two HTML pages, with one being an opening page for an application and the second I have a button on the opening page and I want to be able to click on it and have it take <div id="button"><a href="login.html">Log In</a></div>. If you drag a pair of Next Page/Previous Page arrow buttons, resize the first button, and then select the second button, and choose Object > Transform Again > Transform Again.

How do I link two HTML pages with a button?, <form action="/action_page.php" method="get"> <label for="fname">First name:</​label> <input type="text" id="fname" name="fname"><br><br> Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Full Page Tabs Hover Tabs Top Navigation Responsive Topnav Navbar with Icons Search Menu Search Bar Fixed Sidebar Side Navigation Responsive Sidebar Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Sidebar with Icons Horizontal Scroll Menu Vertical Menu Bottom Navigation Responsive Bottom Nav Bottom Border Nav Links Right Aligned Menu Links Centered Menu Link Equal Width Menu Links Fixed Menu Slide Down Bar on Scroll Hide

HTML button formaction Attribute, <button onclick="displayResult()">Change text</button> <script> Use the id attribute to link to an element with a specified id within a page: <html> <body> In this tutorial, you will learn how to implement a Button and an onclicklistener to open a new activity in your Android application. We will create a Button in an XML graphical layout and implement a button click listener together

HTML Global id Attribute, Given a set of button and the task is to determine the ID of the button when it is jQuery | :button Selector · How to Change the Text of a Button using jQuery? See your article appearing on the GeeksforGeeks main page and help other Geeks. Next. last_page How to check if string contains only digits in JavaScript ? The gather data screen is really the only step that the end-user cares about, but the button at the bottom says "Next", falsely implying there are more steps for the user to complete. The component really needs to say "Finish" to make it clear to the user this is the last step.

  • Your script is wide open to SQL Injection Attack Even if you are escaping inputs, its not safe! Use prepared parameterized statements in either the MYSQLI_ or PDO API's
  • Then I suggest you do a google on What is SQL Injection and read a few articles
  • Also you appear to be calling a js function called getNext but I dont see that function coded anywhere in your script
  • Hello! my PHP or JS level is not advanced, this is my first "big" program. I'll try your code and let you know the results. :) Also im using Mysql-Workbench for storing and collecting data in the database
  • For your question Did you actually find a question from the DB? Yes I did, it worked
  • @ana - those comments are just for you to consider. You should do the validation regardless of whether your test case worked. When you put this code out into the wild, users will attempt to hit your site with .com?id=doesntExit, .com?id=ev1l, .com?id= etc. See here -
  • I need time to understand your code, that's why I'm slow to answer, but I've tried it and there’s an error I don’t know why I'm getting it. This is the error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031 ' and PDOException: SQLSTATE[HY000]: General error: 2031 in the line $stmt = $pdo->query('SELECT * FROM exercises where exercise_id = ?');
  • Hmm. Going to be difficult for me to debug through these comments. If we're not able to figure this out shortly, let's take move this conversation to a chat. One thing to try, make sure you actually have a valid id in the URL. Ex. ...?id=1 Assuming id is a numeric field, can you please change $id = $_GET['id']; to $id = (int)$_GET['id'];? This will cast the value to an integer. If nothing is passed, it will be cast to 0 which the DB should be able to handle. Let me know how that goes.
  • Thanks for your answer biba, I managed to run the 'Next' button as I wanted, with mysqli. You can see the modified answer below. If you think something needs to change please tell me.