doq1969 2017-08-14 18:58
浏览 44
已采纳

如果按下回车键,则Product_ID变量赋值不起作用[复制]

In my project I have:

  1. products list page
  2. single product page

Each row in the products list have a link that passes the product_ID to the single product page as follows:

<!---Products List Page--->
    ....
        <td>
        <a href="singolo_prodotto.php?product_id='.$row['id'].'">Link</a>
        </td>

In the single product page, the product_id is catched as 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, the array value is embedded as 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 I pass from the products lists to the single product page through the above mentioned link, everything works fine. Reloading the single product page everything works fine as well. But if I push the ENTER key being positioned in one of the fields of the "single product" page it 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 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 637

Any idea on how this issue can be fixed?

</div>
  • 写回答

1条回答 默认 最新

  • doubi7496 2017-08-14 19:07
    关注

    The enter key submits your form, but as your form does not have an input with name product_id, the PHP code does not find it and generates the exception.

    Now it depends on what you want:

    • Do you want the form submission system? Then make sure your PHP code can deal with that, and does not expect the product_id to always be defined in the $_GET array, but instead some variables (for named input elements) in the $_POST array.

    • Do you not want the form to be submitted? Then either don't use the form tag, or else add a onsubmit="return false" attribute to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)