Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法检索$\u GET['id']值?_Php_Html_Mysql_Forms_Get - Fatal编程技术网

Php 无法检索$\u GET['id']值?

Php 无法检索$\u GET['id']值?,php,html,mysql,forms,get,Php,Html,Mysql,Forms,Get,我无法从$\u GET变量检索id。我正试图用一个特定的id更新数据库中的一个表。问题是,我可以在地址栏上看到id,但无法通过$\u获取它。这是代码。这里我只分享了部分代码。请检查并指导我 <?php session_start(); include 'connect.php'; $id= $_GET['product_id']; $select_query = "select * from products LEFT JOIN product_description

我无法从$\u GET变量检索id。我正试图用一个特定的id更新数据库中的一个表。问题是,我可以在地址栏上看到id,但无法通过$\u获取它。这是代码。这里我只分享了部分代码。请检查并指导我

<?php
session_start();
include 'connect.php';  
$id= $_GET['product_id'];

$select_query = "select * from products LEFT JOIN product_description 
                ON products.product_id='".$_GET['product_id']."' and 
                product_description.product_id='".$_GET['product_id']."' 
                where products.product_id='".$_GET['product_id']."'     ";

if(!$select_query_run = mysql_query($select_query))
{
    echo mysql_error();
}
else


Notice: Undefined index: product_id in
F:\xampp\htdocs\CMS\update_single_product.php on line 36
**

我做了一些改变,现在它工作了。我还是不知道怎么回事 已修复,但仍能正常工作:


**

使用isset可避免出现问题

if(isset($_GET['product_id'])) {
  $id= $_GET['product_id'];

} else {
  $id = 1;
}
// code here

使用此选项,您可以避免在没有获取值的情况下执行操作。

您应该先检查是否设置了$\u get['product\u id']。变量中还定义了$\u GET['product\u id']。在查询中使用它,不要忘记保护所有输入不受mysql注入的影响

$id = mysql_real_escape_string($_GET['product_id']); $select_query= "SELECT * FROM products LEFT JOIN product_description ON products.product_id='".$id."' and product_description.product_id='".$id."' where products.product_id='".$id."'"; 您可以尝试回显$id,看看会发生什么


在旁注上;MySQL已被弃用。您应该改用mysqli或PDO。

请将您在浏览器地址上看到的url发布到您的.htaccess文件中是否有任何修改?那么您可能在不知不觉中编写了一些不可见的字符。删除第36行中的$\u GET['product\u id'],然后重新编写。请不要剪切和粘贴。错误位置与此处显示的代码不匹配。如果您需要我们帮助,请提供代码直到该行。它给我的id号与地址中显示的id号相同。barTry检查变量是否先设置。如果设置为$\u GET['product\u id']{//执行需要'product\u id'的操作} $id = mysql_real_escape_string($_GET['product_id']); $select_query= "SELECT * FROM products LEFT JOIN product_description ON products.product_id='".$id."' and product_description.product_id='".$id."' where products.product_id='".$id."'";