Hi i am trying to get data from my table defects by user id.
The code keeps displaying No ‘id’ parameter provided in the URL even though there is data in the table.
Here is a screenshot of my table defects.
here is the link i am using to try get the info by id.
echo "<a id='link' href='test1.php?id={$user_data['id']}'>Confirm And Action This Defect</a><br><br>";
here is the code i am using to try retrieve the data.
<?php
// Check if 'id' parameter is set in the URL
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Establish a connection to your database
$connection = new mysqli("localhost", "myname", "my password", "my name");
// Check connection
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
// SQL query with prepared statement to retrieve data based on user ID
$sql = "SELECT * FROM defects WHERE id=?";
$stmt = $connection->prepare($sql);
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Output data of each row
while ($row = $result->fetch_assoc()) {
echo "<p>ID: " . $row["id"] . " - Message: " . $row["message"] . " - Confirm: " . $row["confirm"] . " - Action: " . $row["action"] . "</p>";
}
} else {
echo "0 results";
}
$stmt->close();
$connection->close();
} else {
echo "No 'id' parameter provided in the URL.";
}
?>
Here is the code from the view page.
<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('../inc/config.php');
include(ROOT_PATH . 'inc/functions.php');
include(ROOT_PATH . 'inc/mainheader.php');
include('../inc/database3.php');
// Fetch all users data from database
$result = mysqli_query($mysqli, "SELECT * FROM defects ORDER BY date DESC");
?>
while($user_data = mysqli_fetch_array($result)) {
echo " Date Of Report <br>";
$date = new DateTime($user_data['date']);
echo $date->format('l jS F Y');
echo " <br><br>Name Of Care Home<br>";
echo "".$user_data['name']."";
echo "<br><br>Defects Reported<br>";
echo nl2br($user_data['message']);
echo"<br><br>";
echo "<a id='link' href='test1.php?id={$user_data['id']}'>Confirm And Action This Defect</a><br><br>";
echo '<hr/ color="#000000"><br>';
}
here is the screenshot from this page.
been trying allsorts of ways just cant get it to work.
Thanks