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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.