😕 Yes, I'm a newbie. Trying to teach myself PHP. Ran into a roadblock yesterday.
I've been pouring over various books and web docs to to use the get along with a database query. The best I can get is the column names to appear. I have a very similar query on another page that works just fine, the addition of the $get is throwing it off. My goal is to create dynamic pages based on the prodID. Looking to see where I veered off.
<?php
$host="localhost";
$user="user";
$password="pw";
$db_name ="products";
$db_table="table";
//check connection to db
mysql_connect($host, $user, $password)
or die ("Unable to connect to server");
mysql_select_db($db_name)
or die ("Couldn't retrieve database information");
$Prodid = $_GET['Prodid'];
print($Prodid); //to make sure you're getting what you wanted
$query = "SELECT Prodid, Name, Category, Price FROM testdb WHERE Prodid = '".$_GET['Prodid']."' AND Status = 'A'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<table border ="2">
<?php
echo '<tr><td>Prodid</td><td>Name</td><td>Category</td><td>Price</td></tr>';
$cols = mysql_num_fields( $result );
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['Item_no']."</td>";
echo "<td>".$row['Name']."</td>";
echo "<td>".$row['Category']."</td>";
echo "<td>".$row['Price']."</td>";
echo "</tr>";
}
?>
</table>
This results in the following being displayed:
netted in a table with only labels being displayed.
<table border ="2">
<tr><td>Prodid</td><td>Name</td><td>Category</td><td>Price</td></tr></table>
Thanks in advance, I'm baffled.