dshouse069 Posted May 25, 2006 Share Posted May 25, 2006 I am very new to PHP and one of our current php pages has broken. The creator of these pages left and i got stuck maintaining these pages. It worked for almost a year and then one day we started getting this error. Here is the error that it is gets:Undefined index: Submit in C:\Program Files\Apache Group\Apache2\htdocs\motorcircle\small_part_entry.php on line 41Here is the code for that particular line and below: if ( $_GET['Submit'] == 'Submit'){ print "<P>"; $part_info = array(); $part_count = 0; while(list($key, $val) = each ($_GET)){ $temp = array($key=>$val); // print "$key=>$val<br>"; if ($key != "Submit"){$part_info = array_merge($part_info, $temp);} }Please HELP ME!! Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/ Share on other sites More sharing options...
wildteen88 Posted May 25, 2006 Share Posted May 25, 2006 When doing comparison checks with superglobal arrays always use isset like so:[code] if ( isset( $_GET['Submit'] ) && $_GET['Submit'] == 'Submit'){[/code]That then stops the notice error apearing if Submit is not set. Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/#findComment-38952 Share on other sites More sharing options...
dshouse069 Posted May 25, 2006 Author Share Posted May 25, 2006 [!--quoteo(post=377064:date=May 25 2006, 11:30 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 25 2006, 11:30 AM) [snapback]377064[/snapback][/div][div class=\'quotemain\'][!--quotec--]When doing comparison checks with superglobal arrays always use isset like so:[code] if ( isset( $_GET['Submit'] ) && $_GET['Submit'] == 'Submit'){[/code]That then stops the notice error apearing if Submit is not set.[/quote]I tried that coding and nothing happens when i hit the submit button. It will not allow the database to be updated or anything... Any other ideas?? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/#findComment-38963 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2006 Share Posted May 25, 2006 What method are you using in your form? GET or POST, if it is POST, you should be using the $_POST array, not the $_GET array.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/#findComment-38985 Share on other sites More sharing options...
dshouse069 Posted May 25, 2006 Author Share Posted May 25, 2006 [!--quoteo(post=377098:date=May 25 2006, 01:39 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 25 2006, 01:39 PM) [snapback]377098[/snapback][/div][div class=\'quotemain\'][!--quotec--]What method are you using in your form? GET or POST, if it is POST, you should be using the $_POST array, not the $_GET array.Ken[/quote]Using Get.... Here is entire code if ( $_GET['Submit'] == 'Submit'){ print "<P>"; $part_info = array(); $part_count = 0; while(list($key, $val) = each ($_GET)){ $temp = array($key=>$val); // print "$key=>$val<br>"; if ($key != "Submit"){$part_info = array_merge($part_info, $temp);} } while(list($key, $val) = each ($part_info)){ if ($val == "true"){ $count_index = $key . "_count"; $part_count = $part_info[$count_index]; if (!$part_count){print "You have not specified a quantity for $key. Please correct.";exit;} print "Updating $key with quantity $part_count...<br>"; $query = "SELECT * FROM `$key` ORDER BY last_update DESC LIMIT 1"; $data_result = dbquery($query, $connection); $data_row = mysql_fetch_array($data_result, MYSQL_ASSOC); $part_count = $data_row['inventory'] + $part_count; $query = "INSERT INTO `$key` (inventory, order_number, quantity, last_update) VALUES ($part_count, -1, 0, NOW())"; $result = dbquery($query, $connection); print "Quantity of $key - $data_row[model] has been changed from $data_row[inventory] to $part_count.<br>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/#findComment-38986 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2006 Share Posted May 25, 2006 That's your code of the script that processes your code, not of the form that's passing the data to your script. You need to look at the "<form>" tag.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10444-undefined-index-need-help/#findComment-38999 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.