f.ismayil Posted April 17, 2011 Share Posted April 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233990-notice-indifined-index-userid/ Share on other sites More sharing options...
dcro2 Posted April 17, 2011 Share Posted April 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233990-notice-indifined-index-userid/#findComment-1202688 Share on other sites More sharing options...
f.ismayil Posted April 18, 2011 Author Share Posted April 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233990-notice-indifined-index-userid/#findComment-1202834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.