php - Product_ID variable assignment doesn't work if enter key is pushed -


in project have:

  1. products list page
  2. single product page

each row in products list have link passes product_id single product page follows:

<!---products list page--->     ....         <td>         <a href="singolo_prodotto.php?product_id='.$row['id'].'">link</a>         </td> 

in single product page, product_id catched follows:

<!---single product--->  <!doctype html> <?php  $product_id = $_get['product_id'];  if(!isset($_get['product_id'])){$product_id='13321';}     else { include '../sys/conn.php'; $risultato = mysqli_query ($conn, "  (*...mysql query...*)  ") or die ("invalid query: " . mysqli_error($conn)); mysqli_close($conn);  $row = mysqli_fetch_array($risultato); } ?> 

in each field, array value embedded follows:

<div class="col-lg-3">   <form role="form">      <div class="form-group">        <label>sku</label> <input class="form-control" placeholder="sku code" value = "<?php echo $row['6']; ?>" >       </div>   </form> </div> 

if pass products lists single product page through above mentioned link, works fine. reloading single product page works fine well. if push enter key being positioned in 1 of fields of "single product" page crashes giving these errors:

notice: undefined index: product_id in /applications/xampp/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 6

warning: mysqli_fetch_array() expects parameter 1 mysqli_result, null given in /applications/xampp/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 637

any idea on how issue can fixed?

the enter key submits form, form not have input name product_id, php code not find , generates exception.

now depends on want:

  • do want form submission system? make sure php code can deal that, , not expect product_id defined in $_get array, instead variables (for named input elements) in $_post array.

  • do not want form submitted? either don't use form tag, or else add onsubmit="return false" attribute it.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -