Viewed   118 times

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!

 Answers

4

Try:

<?php

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

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

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

?>
Saturday, September 17, 2022
1

Your form needs the enctype="multipart/form-data" attribute to be able to upload files.

More information here

Sunday, September 25, 2022
5

You're not telling the JS how to send your POST parameters. Change your JS to:

data: { 'testscore':testscore },

This is the equivalent of "testscore=" + testcore in key=value form. It tells JS and PHP that you want the variable testscore to be mapped to the key "testscore", which you'll then pick up with $_POST['testscore']

Edit: See http://api.jquery.com/jQuery.ajax/, "Sending Data to the Server"

Wednesday, August 31, 2022
 
relaxxx
 
4

The action attribute needs to point to the actual script of the page you want to go to.

Try doing this instead:

<form id="loginForm" action="/post/login/index.php" method="post">
Sunday, November 27, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :