Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve Notice: Undefined index: id in C:\xampp\htdocs\invmgt\manufactured_goods\change.php on line 21 [duplicate]

Tags:

php

mysql

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.

Here's the code

<?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>
like image 383
NoviceProgrammer Avatar asked Oct 31 '14 08:10

NoviceProgrammer


1 Answers

You are not getting value of $id=$_GET['id'];

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

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

So, please update the line to:

$id = isset($_GET['id']) ? $_GET['id'] : '';
like image 101
Pupil Avatar answered Nov 01 '22 13:11

Pupil