Forum Moderators: coopster

Message Too Old, No Replies

Undefined index

probably not what you think.

         

SevenLZ

8:13 pm on Oct 2, 2007 (gmt 0)

10+ Year Member


Okay, after scouring the internet for what might cause an Undefined index error, i'm pretty sure there's only one thing, some information is not present in the POST message i'm sending. I just can't figure out why.

In confirm_request.php i have the code:

echo "<form name='form1' method='post' action='confirmed.php'";
echo "<input type='hidden' name='laptopid' value='$laptop_id' id='laptopid'>";
echo "<input type='hidden' name='prismid' value='$prismid' id='prismid'>";
echo "<input type='hidden' name='firstname' value='$firstname' id='firstname'>";
echo "<input type='hidden' name='lastname' value='$lastname' id='lastname'>";
echo "<input type='hidden' name='emailaddress' value='$emailaddress' id='emailaddress'>";
echo "<input type='hidden' name='phone' value='$phone' id='phone'>";
echo "<input type='hidden' name='details' value='$details' id='details'>";
echo "<input type='hidden' name='reason' value='$reason' id='summary'>";
echo "<input type='hidden' name='cod' value='$cod' id='cod'>";
echo "<input type='hidden' name='cid' value='$cid' id='cid'>";
echo "<input type='submit' name='Submit' value='Confirm Request'>";
echo "</form>";

As you can see, this form points at confirmed.php, and sends a variable 'laptopid' whose value comes from $laptop_id earlier in the code. I've tested (on the line right above the form declaration) for the existence of this variable. It exists.

Now, on the receiving side, in confirmed.php, i have:

$prismid = $_POST['prismid'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$emailaddress = $_POST['emailaddress'];
$phone = $_POST['phone'];
$details = $_POST['details'];
$reason = $_POST['reason'];
$cod = $_POST['cod'];
$cid = $_POST['cid'];
$laptop_id = $_POST['laptopid'];

All of these variables function perfectly except $laptop_id. It throws an error Notice: Undefined index: laptopid.

laptop_id is typically a very small integer.

Thank you.

eelixduppy

2:03 am on Oct 3, 2007 (gmt 0)



Hello and Welcome to WebmasterWorld! :)

I don't see why it isn't working as you want because it should. I do see a HTML error, however. You are missing the end of the form tag:


echo "<form name='form1' method='post' action='confirmed.php'>";

check your spelling to see if you have anything wrong. You can also view all the post variables by using the following:


echo '<pre>';
print_r($_POST);
echo '</pre>';

If you can't find it here then the form isn't submitting it properly.

good luck

jatar_k

2:18 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since the laptopid element occurs right after the missing >, as eelix mentioned, it is probably getting absorbed and not getting set properly in the $_POST array

and Welcome to WebmasterWorld SevenLZ

whoisgregg

3:09 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], SevenLZ!

This is also a good example of when validating your pages [validator.w3.org] can help with debugging seemingly-impossible errors. Incorrectly closed HTML elements have bit me many times in the past. :)