Add SQL data to URL with PHP -


i have basic code selects data database , echo's html table , add's link echo'd out data. works fine. want add piece of data database (product_id) url. here code:

<?php $con=mysqli_connect("localhost","root","","db_test"); // check connection if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   } $result = mysqli_query($con,"select * tbl_products");  echo "<table border='1'> <tr> <th>products:</th> </tr>";  while($row = mysqli_fetch_array($result))   {   echo "<tr>";   echo "<td><a href='product.php?id='>" . $row['product_name'] . "</a></td>";   echo "</tr>";   } echo "</table>";  mysqli_close($con); ?> 

i want add product_id database @ end of

<a href='product.php?id=' 

so product_id becomes id of page. how this? have experimented has resulted in numerous errors. sure simple syntax thing it' s bugging me.

you closing tag before placing data href.

i think should work:

echo "<table border='1'> <tr> <th>products:</th> </tr>";  while($row = mysqli_fetch_array($result))   {   echo "<tr>";   echo "<td><a href=\"product.php?id=". $row['product_id'] ."\">" . $row['product_name'] . "</a></td>";   echo "</tr>";   } echo "</table>"; 

answer if doesn't work.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -