PHP MYSQL $_GET['ID'] from table on dynamically generated page -


i have few products stored in table auto-incremented id entitled "product_id".

i have managed create page displays list of products names selected db , dynamically created links each one. let's have product apple. when click on apple takes me view_product_details.php?id=9

but when click apple, view_product_details.php page tells me "notice: undefined index: product_id in c:\xampp\htdocs\working\product-website-exercise\view_product_details.php on line 16"

<?php   //$result = mysql_query("select * temaproduct.products id = '".mysql_real_escape_string($_get['product_id'])."'");           $id = $_get['product_id']; //this line 16          $result = mysqli_query($conn,"select * products id = $id");          echo $result['product_description'];  echo "<br>"; var_dump($result);  ?> 

i have tried different queries can't figure out, please me establish connection can read other fields table on view_product_details page, based on product_id.

edit: thank guys, help, here code works now, if needs snippet:

<?php $id = intval($_get['id']);  $sql = mysqli_query($conn,"select * products product_id = ".$id); if(mysqli_num_rows($sql)){     $product_data = mysqli_fetch_array($sql);     echo "<h2><center>".$product_data['title']."</h2></center>"; } ?> 

you using id query string in url as:

view_product_details.php?id=9 

so, need id as:

$id = $_get['id']; //this line 16 

second issue in code that, can not result database without using mysqli_fetch_* function.

echo $result['product_description']; // return nothing 

your modified code:

<? $id = intval($_get['id']);  $sql = mysqli_query($conn,"select * products id = ".$id); if(mysqli_num_rows($sql)){     $result = mysqli_fetch_array($sql);     echo $result['product_description']; } else{     echo "no record found"; } ?> 

suggestion:

you need 1 more thing, please use intval() function if 1 pass string or else in query string query not return error return 0 record like:

example:

view_product_details.php?id=abcdjunk 

than convert 0 as:

$id = intval($_get['id']);  

for future visitors:

after debugging, found error "unknown column id"

so correct query op mentioned (column name product_id):

select * hangouts product_id = 9 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -