Jump to content

Problem with $_GET in query


doucie

Recommended Posts

OK this is my (very basic I know) code for getting a record from the database via a link from the previous page. 
The query_number is passed through the URL OK. 
The URL looks like this - http://localhost/Query%20System/query_details.php?=query_number=6
However, the table header displays OK but the result of the query does not.  HELP!


$result=mysql_query("SELECT * FROM query WHERE query_number='" . $_GET['query_number'] ."'");

echo "<table width=\"100%\" border=\"1\" align=\"center\" bordercolor=\"#000099\" cellspacing=\"0\" cellpadding=\"5\"
<tr><td>Query Number</td>
<td>Query Type</td>
<td>Status</td>
<td>Client</td>
<td>Client Ref</td>
<td>DebtRef</td>
<td>Date/Time Entered</td>
<td>User</td>
<td>Notes</td>
</tr> ";

while ($row=mysql_fetch_array($result)){
$query_number=$row['query_number'];
$query_type=$row['query_type'];
$query_status=$row['query_status'];
$client=$row['client'];
$client_ref=$row['client_ref'];
$debt_ref=$row['debt_ref'];
$query_date=$row['query_date'];
$user=$row['user'];
echo "<tr><td>$query_number</td>";
echo "<td>$query_type</td>";
echo "<td>$query_status</td>";
echo "<td>$client</td>";
echo "<td>$client_ref</td>";
echo "<td>$debt_ref</td>";
echo "<td>$query_date</td>";
echo "<td>$user</td>";
}
echo "</table>";
?>
Link to comment
https://forums.phpfreaks.com/topic/32203-problem-with-_get-in-query/
Share on other sites

Replace this line:
[code]<?php
$result=mysql_query("SELECT * FROM query WHERE query_number='" . $_GET['query_number'] ."'");
?>[/code]

with
[code]<?php
$query = "SELECT * FROM query WHERE query_number='" . $_GET['query_number'] ."'";
$result=mysql_query($query) or die("There was a problem with the query: $query<br>" . $mysql_error());
?>[/code]
If you are getting any errors mysql errors this will show them to you.

The other option is that there might be no data returned from the query.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.