Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm doing a code where the main page has titles of some exercises (stored in a Mysql database) and depending on what title the user clicks (with links), I want the title and the question itself in another page: ‘2.php’. The questions will also be taken from the database. Im trying to use a GET parameter in the exercise link with the id of the exercise. Then in ‘2.php’, get the exercise with that id from the database

This is some of the code that I've done so far but I'm stuck. Could you give me some advice?
Thank you.

What I have tried:

Exercises.php – In here I have all of the titles of the exercises displayed.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";

<pre lang="PHP">$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "SELECT * FROM exercises";
$result = $conn->query($sql);

?>

<?php
while($row = $result->fetch_assoc())
{
    ?>
    <tr>
        <td><?php echo $row["exercise_id"]; ?></td>
        <td><a name="search" href="http://localhost/PHP%20Pages/2.php" target="_blank"><?php echo $row["title"]; ?></a></td>
        <td><?php echo $row["difficulty"]; ?></td>

    </tr>
    <?php
}
?>


2.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";

$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM exercises"; /*Select from table name: exercises*/
$result = $conn->query($sql); /*Check connection*/


    $result = $conn->query($sql);
    while($row = $result->fetch_assoc()) {
        echo $row["exercise_id"] . ". " .  $row["title"] . $row["text"] . "<br>";
    }
}
?>
Posted
Updated 3-Aug-18 2:04am

1 solution

Use header("location: your_link");

Instead of href.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900