Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined index error PHP

I'm new in PHP and I'm getting this error:

Notice: Undefined index: productid in /var/www/test/modifyform.php on line 32

Notice: Undefined index: name in /var/www/test/modifyform.php on line 33

Notice: Undefined index: price in /var/www/test/modifyform.php on line 34

Notice: Undefined index: description in /var/www/test/modifyform.php on line 35

I couldn't find any solution online, so maybe someone can help me.

Here is the code:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">    <input type="hidden" name="rowID" value="<?php echo $rowID;?>">     <p>       Product ID:<br />       <input type="text" name="productid" size="8" maxlength="8" value="<?php echo $productid;?>" />    </p>     <p>       Name:<br />       <input type="text" name="name" size="25" maxlength="25" value="<?php echo $name;?>" />    </p>     <p>       Price:<br />       <input type="text" name="price" size="6" maxlength="6" value="<?php echo $price;?>" />    </p>     <p>       Description:<br />       <textarea name="description" rows="5" cols="30">       <?php echo $description;?></textarea>    </p>     <p>       <input type="submit" name="submit" value="Submit!" />    </p>    </form>    <?php    if (isset($_POST['submit'])) {       $rowID = $_POST['rowID'];       $productid = $_POST['productid']; //this is line 32 and so on...       $name = $_POST['name'];       $price = $_POST['price'];       $description = $_POST['description'];  } 

What I do after that (or at least I'm trying) is to update a table in MySQL. I really can't understand why $rowID is defined while the other variables aren't.

Thank you for taking your time to answer me. Cheers!

like image 408
LPoblet Avatar asked May 16 '12 07:05

LPoblet


People also ask

How do I fix undefined index error in PHP?

To resolve undefined index error, we make use of a function called isset() function in PHP. To ignore the undefined index error, we update the option error_reporting to ~E_NOTICE to disable the notice reporting.

What causes Undefined index in PHP?

Notice Undefined Index in PHP is an error which occurs when we try to access the value or variable which does not even exist in reality. Undefined Index is the usual error that comes up when we try to access the variable which does not persist.

How do I get rid of notice Undefined index?

You can get rid of the PHP undefined index notice by using the isset() function. The PHP undefined variable notice can be removed by either using the isset() function or setting the variable value as an empty string.


1 Answers

Try:

<?php  if (isset($_POST['name'])) {     $name = $_POST['name']; }  if (isset($_POST['price'])) {     $price = $_POST['price']; }  if (isset($_POST['description'])) {     $description = $_POST['description']; }  ?> 
like image 55
Adam Avatar answered Oct 13 '22 00:10

Adam