How to solve Notice Undefined index id in C xampp htdocs invmgt manufactured goods change php on line 21

0 votes

I am having an error in the PHP code saying "Notice: Undefined index".

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>

As I am a beginner I cant solve this issue. Can someone help me with this?

Apr 30, 2022 in Other DevOps Questions by Kichu
• 19,040 points
9,189 views

1 answer to this question.

0 votes

The issue is that you are using the git id before it gets initialized. To solve this, use PHP's inbuilt isset() function to check whether the variable is defied or not.

So, update the line to:

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

This will remove the notice that you are facing. 

answered May 1, 2022 by narikkadan
• 63,600 points

Related Questions In Other DevOps Questions

0 votes
1 answer

How to get issues count based on rules in a sonar project?

There are API docs in the footer ...READ MORE

answered May 4, 2018 in Other DevOps Questions by DareDev
• 6,890 points
2,843 views
0 votes
0 answers
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
10,540 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,250 points
1,268 views
0 votes
2 answers
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP