...

View Full Version : Undefined index: Submit in localhost on line 19



captainer
04-22-2012, 09:59 PM
Hello,
I have a forum I am creating, when load it in my browser, the forum loads and displays correctly, however, I get an error statingnotice: Undefined index: Submit in C:\xampp\folder\file.php on line 19 Can someone explain what is causing the error, here is my code.


<?php
session_start();

include ('dbc.php');

//Form Error Checking.
if ($_POST['Submit'] == 'Submit')
//if (!isset($_POST['Submit']) || ($_POST['Submit'] != 'Submit'))
{
//Verify Service Order# is Eight Charecters.
if (strlen($_POST['servord_num']) < 8)
{
echo("<br><br><br><br><br><br>");
die ("ERROR: Invalid Service Order #..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Verify Customer Reference # is 11 Charectors
if (strlen($_POST['custref_num']) < 11)
{
echo("<br><br><br><br><br><br>");
die ("ERROR: Invalid Customer Reference #..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Verify Technicians Name
if (strlen($_POST['tech_name']) < 5)
{
echo("<br><br><br><br><br><br>");
die ("ERROR: Please Enter Your First & Last Name..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Verify Technicians Phone
if (strlen($_POST['tech_phone']) < 10)
{
echo("<br><br><br><br><br><br>");
die ("ERROR: Please Enter Your Contact Phone..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Verify Technicians E-Mail
if (strlen($_POST['tech_email']) < 5)
{
echo("<br><br><br><br><br><br>");
die ("Incorrect email format, Please enter valid email address..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Dispatching Company
if (strlen($_POST['reportto_comp']) < 5)
{
echo("<br><br><br><br><br><br>");
die ("Enter Company Dispatched From..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Servicing Company
if (strlen($_POST['serv_comp']) < 3)
{
echo("<br><br><br><br><br><br>");
die ("Enter Name Of Company Where Equipment Is Being Serviced..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Client's Address
if (strlen($_POST['client_addr']) < 10)
{
echo("<br><br><br><br><br><br>");
die ("Address Of Company Where Equipment Is Being Serviced..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Clien's Phone
/*if (strlen($_POST['client_phone']) < 10)
{
echo("<br><br><br><br><br><br>");
die ("Enter Clients Ten or Eleven Digit Phone Number..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}*/
//Service Date
if (strlen($_POST['serv_month']) < 2 && ($_POST['serv_day']) < 2 && ($_POST['serv_year']) < 4)
{
echo("<br><br><br><br><br><br>");
die ("Incorrect Date Format, Enter Correct Date In The Proper Format \"mm/dd/yyyy\"..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Arrival Time At Clients Location.
if (strlen($_POST['arv_time']) < 5)
{
echo("<br><br><br><br><br><br>");
die ("Enter The Time You Arrived At Clients Site..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Departure Time From Clients Location.
if (strlen($_POST['dep_time']) < 5)
{
echo("<br><br><br><br><br><br>");
die ("Enter Time You Departed From Clients Site..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}
//Milage OneWay.
if (strlen($_POST['miles_oneway']) < 1)
{
echo("<br><br><br><br><br><br>");
die ("Enter The Miles Traveled Oneway To Clients Location..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
<p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div>
</div>
</div><?php
}


//Query To Insert Date Into MySQL Database.
$insert = mysql_query("INSERT INTO invoice
(`servord_num`,`custref_num`,`tech_name`,`tech_phone`,`tech_email`,`reportto_comp`,`serv_comp`,`clie nt_addr`,`client_phone`,`serv_month`,`serv_day`,`serv_year`,`arv_time`,`dep_time`,`miles_oneway`,`pa rking`,`toll`)
VALUES
('$_POST[servord_num]','$_POST[custref_num]','$_POST[tech_name]','$_POST[tech_phone]','$_POST[tech_email]','$_POST[reportto_comp]','$_POST[serv_comp]','$_POST[client_addr]','$_POST[client_phone]','$_POST[serv_month]','$_POST[serv_day]','$_POST[serv_year]','$_POST[arv_time]','$_POST[dep_time]','$_POST[miles_oneway]','$_POST[parking]','$_POST[toll]')") or die(mysql_error());

$message =
"Thank you for registering with Fantasy Nails & Spa.\nYour login details are displayed below, please save this information in a safe place...\n\n
User Email: $_POST[tech_email] \n\n\n
You may login by clicking the link below or copying and pasting the url into your browser:\n
http://norcopathfinders.com/mergedfantasy/login.php or

_____________________________________________
Thank you. This is an automated response. PLEASE DO NOT REPLY.
";

echo("Time Loged Successfully! Select the \"History\" link to see a list of the times inputed into the database....<br>Please check your e-mail address for a link to log into your account.");
echo("<br><br><br><br><br><br><br><br><br><br>");
?><p></p>
<p>&nbsp;</p>
</div>
<div id="content_bottom"></div><?php

exit;
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; }

// Populate Password Fields With Random Password.


/**
* The letter l (lowercase L) and the number 1
* have been removed, as they can be mistaken
* for each other.
*/

function createRandomPassword() {

$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;

while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}

return $pass;

}

// Usage
$password = createRandomPassword();
//echo "Your random password is: $password";
//echo "You are not authorized to view the contents of this page. Contact your site administrator.";




?>

Forum:
<tr>
<td></td>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
<td></td>
</tr>
</form>

felgall
04-23-2012, 12:03 AM
I think the line causing that error is:


if (strlen($_POST['custref_num']) < 11)

if $_POST['custref_num'] doesn't exist then the value being passed to strlen() is invalid.

captainer
04-23-2012, 11:23 PM
Line 19 in my code is
if ($_POST['Submit'] == 'Submit') I believe that the submit button may not be validating, however, when I fill in the form, and select submit, It does enter the fields in mysql backend database in the proper fields. I'm not sure why I get this error when seems to be passing data correctly?

Fou-Lu
04-23-2012, 11:27 PM
Not sure why this is in the mysql forum; moving to PHP.
None of these lines match up. But the error has to be right here since its the only use of an offset called 'Submit':


//Form Error Checking.
if ($_POST['Submit'] == 'Submit')

That should be:


if (isset($_POST['Submit']) && $_POST['Submit'] == 'Submit')

Although due to IE you shouldn't check on this field as it will not obey sending its successful submit button unless its actually clicked. Use an isset check on each field that is expected instead: isset($_POST['servord_num'], $_POST['custref_num'], ....). You'll also want to look into SQL injections and how to secure your code.

tangoforce
04-24-2012, 01:43 AM
I get an error statingnotice: Undefined index: Submit in C:\xampp\folder\file.php on line 19



I think the line causing that error is:


if (strlen($_POST['custref_num']) < 11)

if $_POST['custref_num'] doesn't exist then the value being passed to strlen() is invalid.

felgall, do you actually try to understand these things before posting? - This isn't the first or second time I've noticed your posts pinning down the wrong issue.

As Fou says, (more 3explicit information is in my signature) IE does not send the submit button value if you don't click it with the mouse pointer. That means if you have a cursor in the text box and hit the return key then $_POST['Sumit'] will not exist causing an undefined index error.

@captainer for more information click the link that relates to this in my signature. There is also a video demonstration of the IE quirk in action.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum