I am working on a shopping cart in PHP and I seem to be getting this error \"Notice: Undefined index:\" in all sorts of places. The error refers to the similar bit of coding
<?php
if ($_POST['parse_var'] == "contactform"){
$emailTitle = 'New Email From KumbhAqua';
$yourEmail = 'xyz@gmail.com';
$emailField = $_POST['email'];
$nameField = $_POST['name'];
$numberField = $_POST['number'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br />
Name: $nameField <br />
Message: $messageField <br />
EOD;
$headers = "from: $emailField\r\n";
$headers .= "Content-type: text/htmml\r\n";
$success = mail("$yourEmail", "$emailTitle", "$body", "$headers");
$sent ="Thank You ! Your Message Has Been sent.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>:: KumbhAqua ::</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<link rel="stylesheet" href="style1.css" type="text/css">
</head>
<body>
<div class="container">
<div class="mainHeader">
<div class="transbox">
<p><font color="red" face="Matura MT Script Capitals" size="+5">Kumbh</font><font face="Matura MT Script Capitals" size="+5" color= "skyblue">Aqua</font><font color="skyblue"> Solution</font></p>
<p ><font color="skyblue">Your First Destination for Healthier Life.</font></p>
<nav><ul>
<li> <a href="KumbhAqua.html">Home</a></li>
<li> <a href="aboutus.html">KumbhAqua</a></li>
<li> <a href="services.html">Products</a></li>
<li class="active"> <a href="contactus.php">ContactUs</a></li>
</ul></nav>
</div>
</div>
</div>
<div class="main">
<div class="mainContent">
<h1 style="font-size:28px; letter-spacing: 16px; padding-top: 20px; text-align:center; text-transform: uppercase; color: #a7a7a7"><font color="red">Kumbh</font><font color="skyblue">Aqua</font> Symbol of purity</h1>
<div class="contactForm">
<form name="contactform" id="contactform" method="POST" action="contactus.php" >
Name :<br />
<input type="text" id="name" name="name" maxlength="30" size="30" value="<?php echo "nameField"; ?>" /><br />
E-mail :<br />
<input type="text" id="email" name="email" maxlength="50" size="50" value="<?php echo "emailField"; ?>" /><br />
Phone Number :<br />
<input type="text" id="number" name="number" value="<?php echo "numberField"; ?>"/><br />
Message :<br />
<textarea id="message" name="message" rows="10" cols="20" value="<?php echo "messageField"; ?>" >Some Text... </textarea>
<input type="reset" name="reset" id="reset" value="Reset">
<input type="hidden" name="parse_var" id="parse_var" value="contactform" />
<input type="submit" name="submit" id="submit" value="Submit"> <br />
<?php echo "$sent"; ?>
</form>
</div>
<div class="contactFormAdd">
<img src="Images/k1.JPG" width="200" height="200" title="Contactus" />
<h1>KumbhAqua Solution,</h1>
<strong><p>Saraswati Vihar Colony,<br />
New Cantt Allahabad, 211001
</p></strong>
<b>DEEPAK SINGH RISHIRAJ SINGH<br />
8687263459 8115120821 </b>
</div>
</div>
</div>
<footer class="mainFooter">
<nav>
<ul>
<li> <a href="KumbhAqua.html"> Home </a></li>
<li> <a href="aboutus.html"> KumbhAqua </a></li>
<li> <a href="services.html"> Products</a></li>
<li class="active"> <a href="contactus.php"> ContactUs </a></li>
</ul>
<div class="r_footer">
Copyright © 2015 <a href="#" Title="KumbhAqua">KumbhAqua.in</a> Created and Maintained By- <a title="Randheer Pratap Singh "href="#">RandheerSingh</a> </div>
</nav>
</footer>
</body>
</html>
enter code here
How I can get rid of it so it doesnt display it?
People here are trying to tell you that it's unprofessional (and it is), but in your case you should simply add following to the start of your application:
error_reporting(E_ERROR|E_WARNING);
This will disable E_NOTICE reporting. E_NOTICES are not errors, but notices, as the name says. You'd better check this stuff out and proof that undefined variables don't lead to errors. But the common case is that they are just informal, and perfectly normal for handling form input with PHP.
Also, next time Google the error message first.