Author Topic: I can't see the error  (Read 155 times)

Leandro

  • Guest
I can't see the error
« on: May 16, 2012, 01:44:07 AM »
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:

PHP Code: [Select]
<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 don't.

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

richei

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1135
  • Karma: 23
    • View Profile
Re: I can't see the error
« Reply #1 on: May 16, 2012, 11:23:16 AM »
Undefined index is just means that you're trying to use a variable that hasn't been created yet.  Couple ways to fix it. 1 - before the section that uses them starts, default the varaibles to something, or 2 - use if(isset()) statements on each one.  This can have some unintended side effects though.