如何解决注意:未定义的索引:第21行的C:\ xampp \ htdocs \ invmgt \ manufactured_goods \ change.php中的id [英] How to solve Notice: Undefined index: id in C:\xampp\htdocs\invmgt\manufactured_goods\change.php on line 21

查看:47
本文介绍了如何解决注意:未定义的索引:第21行的C:\ xampp \ htdocs \ invmgt \ manufactured_goods \ change.php中的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP代码有一个问题,上面写着注意:未定义的索引",我相信它非常简单,因为我是一个初学者,所以我不完全知道问题出在哪里,所以请帮帮我.

I have a problem with my PHP code saying that "Notice: Undefined index" I am sure its very simple, since I am a beginner i am not getting well what is wrong exactly so please help me.

这是代码

<?php require_once('../Connections/itemconn.php'); ?>
    <?php   

    $id=$_GET['id']; 

        $query=mysql_query("select * from manuf where id='$id' ")or die(mysql_error());
        $row=mysql_fetch_array($query);

        ?>

<form action="updateprice.php" method="post" enctype="multipart/form-data">
  <table align="center">
   <tr>
   <td> <label><strong>Item Name</strong></label></td>
     <td> <label> <?php echo $row['itemname']; ?></label><input type="hidden" name="id" value="<?php echo $id; ?> " />
     <br /></td>
    </tr>
    <tr>

     <td><label><strong>Unit price </strong></label></td>
  <td> <input type="text" name="pass" value="<?php echo $row['unitprice']; ?> " /><br /></td>
  </tr>

    <tr>
  <td> 
          <input type="reset" name="Reset" value="CANCEL" />
      <br></td>


     <td> 
          <input type="submit" name="Submit2" value="Update" />      </td>
   </tr>
</table>
</form>
</body>
</html>

推荐答案

您没有获得$id=$_GET['id'];

并且您正在使用它(在它初始化之前).

And you are using it (before it gets initialised).

使用内置的 isset()函数中的php来检查变量是否为 是否违抗.

Use php's in built isset() function to check whether the variable is defied or not.

因此,请将行更新为:

$id = isset($_GET['id']) ? $_GET['id'] : '';

这篇关于如何解决注意:未定义的索引:第21行的C:\ xampp \ htdocs \ invmgt \ manufactured_goods \ change.php中的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆