0

I have a page which contains a table. The 'change_id' field contains hyperlinks which direct the user to a different page with an overview of that change_id's details.

'<td><a href="home2.php?changeid=' . $row['change_id'] . '">' . $row['change_id'] . '</a></td>';

Now, just to test that the change_id is being received on the home2.php page, I used the following code:

<?php 
include 'config.php';
$change_id=$_GET['change_id'];
print_r($_GET);
?>

This test successfully displayed the correct change id's:

Array ( [changeid] => 1006 )

Now, when I go to query the SQL Database using the change_id it doesn't work as desired.

<?php 
include 'config.php';
$change_id=$_GET['change_id'];
$query1 = "SELECT * FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result = mysqli_query($conn, $query1);

echo  "<fieldset><legend><strong>New Requests:</legend></strong>
<table border=4 bordercolor=black class=table>
<tr>
<th>Change ID:</th>
<th>Customer Name:</th>
<th>Change Requestor:</th>
<th>Date CR raised:</th>
<th>CPM/Ticket:</th>
<th>Out of Hours:</th>
<th>Change Category:</th>
</tr>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['change_id'] . "</td>";
echo "<td>" . $row['customer_name'] . "</td>";
echo "<td>" . $row['change_requestor'] . "</td>";
echo "<td>" . $row['date_cr_raised'] . "</td>";
echo "<td>" . $row['cpm_ticket'] . "</td>";
echo "<td>" . $row['out_of_hours'] . "</td>";
echo "<td>" . $row['category_of_change'] . "</td>";
echo "</tr>";
}  
echo "</table></fieldset><br><br><br>";
?>

The table are headers are shown without any data. Any ideas on how to fix? Thanks in advance

2
  • 1
    Is your change_id an int in the table? Commented Apr 20, 2017 at 10:31
  • 1
    Auto Incremented INT Commented Apr 20, 2017 at 10:39

1 Answer 1

1

You are setting $change_id to $_GET['change_id']

However you are passing $_GET the parameter name of changeid

If you change

$change_id = $_GET['change_id'];

To

$change_id = $_GET['changeid'];

It should work as expected :)

Sign up to request clarification or add additional context in comments.

2 Comments

its working now without the '_'. Why is this the case?
Because as far as PHP is concerned they are two different variables/parameters. Make sure you keep an eye on the CaSe and any symbols you use in PHP :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.