LPoblet LPoblet - 1 year ago 107
PHP Question

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

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

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;?>">

Product ID:<br />
<input type="text" name="productid" size="8" maxlength="8" value="<?php echo $productid;?>" />

Name:<br />
<input type="text" name="name" size="25" maxlength="25" value="<?php echo $name;?>" />

Price:<br />
<input type="text" name="price" size="6" maxlength="6" value="<?php echo $price;?>" />

Description:<br />
<textarea name="description" rows="5" cols="30">
<?php echo $description;?></textarea>

<input type="submit" name="submit" value="Submit!" />
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
is defined while the other variables aren't.

Thank you for taking your time to answer me.

Answer Source



if(isset($_POST['name'])){ $name = $_POST['name']; } 
if(isset($_POST['price'])){ $price = $_POST['price']; } 
if(isset($_POST['description'])){ $description = $_POST['description']; } 

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download