Jump to content

Notice: Undefined index


FUNKAM35

Recommended Posts

<form name=\"form1\" ACTION=\"$_SERVER[REQUEST_URI]\" METHOD=\"POST\">Your First Name<br><input name=\"first\" value = \"$first\" type=\"text\" id=\"first\" size=\"25\"><br><br>Last Name<br><input name=\"last\" value = \"$last\" type=\"text\" id=\"last\" size=\"25\"><br><br>Email<br><input name=\"email\" value = \"$email\" type=\"text\" id=\"email\" size=\"25\"><br><br>Telephone Number<br><input name=\"phone\" value = \"$phone\" type=\"text\" id=\"phone\" size=\"25\"><br><br><label for=\"comments\">Comments</label><textarea name=\"comments\" cols=\"18\" rows=\"4\" class=\"txt\" id=\"comments\"></textarea><div style=\"visibility:hidden\"><input name=\"email2\" type=\"text\" size=\"45\" id=\"email2\" > </div><input type=\"submit\" name=\"Submit\" value=\"Submit\" class=\"tpc4\"></form>\n";

Hi I am getting the error message  Notice: Undefined Index on the following form before submission

I would like to fix this rather than suppress errors

Any help would be much appreciated

 

 

Link to comment
https://forums.phpfreaks.com/topic/297569-notice-undefined-index/
Share on other sites

@FUNKAM35 - Does your page have multiple forms? If not, your $_POST variable should be "first" and not "first1"...unless there is more to your form that's not being shown.

 

To avoid errors being shown before a form is submitted, you could check if the form was submitted before using $_POST. However, you would still need to set variables like $first so that errors don't come up while the form is being displayed. Here's a quick example:

<?php
//IF FORM WAS SUBMITTED
if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $first = $_POST['first'];
    //get the rest of the form information
 
//ELSE...INITIALIZE FIELDS
} else {
    $first = '';
    //initialize other variables...
}
 
//dispaly form...
?>

Archived

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

×
×
  • Create New...

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.