I want to pass the id value of the PHP generated button from the theory.php
file to the theory1.php
file.
code show as below:
//theory.php file require('components/db.php'); $query = "SELECT * FROM `courses`"; $result = mysqli_query($connect, $query) or die("Error:" . mysqli_error($connect));; $numrows = mysqli_num_rows($result); for ($i = 0; $i < $numrows; $i++) { $query = "SELECT * FROM `courses` WHERE courseID = '$i'"; $result = mysqli_query($connect, $query) or die("Error:" . mysqli_error($connect));; $rowQuery = mysqli_fetch_assoc($result); $_SESSION['course_ID'] = $i; echo ' <div class="card"> <img class = "cardImage" src="'; echo $rowQuery['imageLink']; echo '" alt="Course 1"> <h3>'; echo $rowQuery['courseName']; echo '</h3> <p>'; echo $rowQuery['courseTextOne']; echo '</p> <a href="theory1.php?course_ID=$i" class="button">Proceed</a> </div>'; //a - is a button which needs to have an ID to pass to theory1.php }
This code generates a card with a button. I want each button to store the corresponding ID of the course in the MySQL database. This ID needs to be passed to another page based on the button (card) clicked so that the correct data can be retrieved from the database in the future.
solution
Theory.php:
theory1.php: