Jump to content

Archived

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

dshouse069

Undefined index!! Need help

Recommended Posts

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 41




Here 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!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--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>";
}
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.