0

I am having some problems with my PHP code. I have one php file that displays a list of records from MySQL database and I want it when user clicks on a record they get further detail on that record. I have created the link to the second php file but I keep getting "Data Error" when I click on any record.

I have code in the php that checks if the User_ID is a number and I have checked the database set up to make sure the field is formatted as an INT (it is a foreign key as well so the number is unique).

The php code from the first file is:

<table>


<?php 
// Connects to your Database 
mysql_connect("server","username","password") or die(mysql_error()); 
mysql_select_db("databsename") or die(mysql_error()); 
$data = mysql_query("SELECT `User_ID`,`Market_Name`, `Days`, `Time`,`Image`  FROM `markets_info`ORDER BY `Market_Name`; ")  
or die(mysql_error()); 
echo "<tr><th>Name</th><th>Day</th><th>Time</th><th>Image</th></tr>";

while($info = mysql_fetch_array( $data )) 

{  
echo "<tr>"; 
echo "<td><a href=mktdetails.php?id=$info[User_ID]>$info[Market_Name]</a></td> "; 
echo "<td>".$info['Days'] . " </td> "; 
echo "<td>".$info['Time'] . " </td> "; 
echo  "<td>".'<img src="' . $info['Image'] . '" height="80" width="150" />'."</td> ";
echo"</tr>"; 


} 


?> 

</table>

mktdetails.php is:

<table style="width:860px" border="1" class="auto-style15">

<?php 
// Connects to your Database 
mysql_connect("server","username","password") or die(mysql_error()); 
mysql_select_db("databse") or die(mysql_error()); 

$id=$_GET["User_ID"]; // Collecting data from query string
if(!is_numeric($id)){ // Checking data it is a number or not
echo "Data Error";
exit;
}

$data=mysql_query("SELECT * FROM `markets_info` WHERE `User_ID`=$id");
$row=mysql_fetch_object($data);
echo mysql_error();

echo"<tr><td>$row->Market_Name</td></tr>";
echo"<tr><td>$row->Days</td></tr>";
echo"<tr><td>$row->Time</td></tr>";
echo"<tr><td>$row->Description</td></tr>";


?> 
</table>
1
  • 1
    Is the url on mktdetails.php correct? Maybe you should use some quotes in your strings: <a href='mktdetails.php?id={$info[User_ID]}'> Commented Sep 6, 2013 at 10:16

1 Answer 1

1

It seems that you don't pass via GET 'User_ID'

echo "<td><a href=mktdetails.php?id=$info[User_ID]>$info[Market_Name]</a></td> "; 

Should be something like:

echo "<td><a href='mktdetails.php?User_ID=".$info[User_ID]."'>".$info[Market_Name]."</a></td> "; 
Sign up to request clarification or add additional context in comments.

1 Comment

An answer came up saying in the mktdetails.php page to change $id=$_GET["User_ID"]; to $id=$_GET["id"]; and the page is uploading now. (I don't know where the answer is gone but thank you!!!) Woohoo!!!!!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.