Jump to content


Photo

Undefined index!! Need help


  • Please log in to reply
5 replies to this topic

#1 dshouse069

dshouse069
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 May 2006 - 04:02 PM

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



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 May 2006 - 04:30 PM

When doing comparison checks with superglobal arrays always use isset like so:
if ( isset( $_GET['Submit'] ) && $_GET['Submit'] == 'Submit'){

That then stops the notice error apearing if Submit is not set.

#3 dshouse069

dshouse069
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 May 2006 - 05:42 PM

[!--quoteo(post=377064:date=May 25 2006, 11:30 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 25 2006, 11:30 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
When doing comparison checks with superglobal arrays always use isset like so:
if ( isset( $_GET['Submit'] ) && $_GET['Submit'] == 'Submit'){

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

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 May 2006 - 06:39 PM

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

#5 dshouse069

dshouse069
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 May 2006 - 06:43 PM

[!--quoteo(post=377098:date=May 25 2006, 01:39 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 25 2006, 01:39 PM) View Post[/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>";
}
}

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 May 2006 - 08:04 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users