Jump to content

Notice: Indifined index: userid


f.ismayil

Recommended Posts

When I try to compile the following code, I receive a warning:

 

Notice: Indifined index: userid

 

$letters = array_merge(range("A", "Z"), array("&#198", "&#216", "&#197"));

mysql_select_db("okern", $link_id);

 

$userid = $_POST['userid'];

echo "$userid";

 

foreach($letters as $letter) {

  if(isset($_POST[$letter])) {

    $product = $letter . '1';

    $antall = $letter . '2';

    $enhet = $letter . '3';

   

    $melding = $_POST['melding'];

   

    $query = "INSERT INTO orders VALUES ('farhad', '$product', '$antall', '2011-04-18', '$melding')";

    $result = mysql_query($query) or die(mysql_error());

  }

}

 

When I try to compile my php file in phpDesigner I accept Notice. But, when I run the same php file from browser echo "$userid"; code workes. And I see the userid transferred from another php file on the screen. So I do not understand why I get this notice in compilation process.

Link to comment
https://forums.phpfreaks.com/topic/233990-notice-indifined-index-userid/
Share on other sites

Right, that warning just means that $_POST['userid'] isn't set. This variable is only set when a form is submitted to this page with the POST method. When phpDesigner checks it, nothing's been submitted, right? So nothing in $_POST will be set.

 

You should be using isset like you are doing inside the foreach loop.

Now I understood the issue and modified my code. Anyway I think PHP should consider that $_POST['userid'] has not been submitted and allow me to compile. Now I understood and in future to avoid Notices I will always use isset() function.

Thank you very much dcro2

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.