Sending variables from one PHP page to another

后端 未结 3 1365
长情又很酷
长情又很酷 2021-01-24 17:04

I\'m building a quiz web application that is dynamically generated from a database on my server. I have pretty much implemented all the functionality, the only missing piece is

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 17:24

    Use $_GET.

    First, you're going to want to change this line

    echo '' . $row['title'] . '
    ';

    To something like this:

    echo '' . $row['title'] . '
    ';

    And then in quiz.php, retrieve the appropriate quiz using $_GET['id'] as your primary key to look it up in the database.

    You should store your quiz title there too (in the db).

    $_GET is appropriate here because you're just using an ID to determine which quiz to display. There's no need for confidentiality here. You would use $_POST when you're submitting form data which alters the database. $_SESSION is useful for storing basic login info and other stuff that must persist across multiple pages for the life of the session, such as wizard forms.

提交回复
热议问题