Hello everyone,
I’m a complete beginner to php. I am trying to learn PHP through self-study and have reached an obstacle which I’ve not been able to overcome and need. The problem is that when I open my php form in a web browser the following error message appears.
Notice: Undefined index: firstname in C:\xampp\htdocs\form_1\CONTACT_DETAILS_dataentry.php on line 20
Notice: Undefined index: surname in C:\xampp\htdocs\form_1\CONTACT_DETAILS_dataentry.php on line 21
Notice: Undefined index: telephone_no in C:\xampp\htdocs\form_1\CONTACT_DETAILS_dataentry.php on line 22
Notice: Undefined index: emailaddress in C:\xampp\htdocs\form_1\CONTACT_DETAILS_dataentry.php on line 23
I'm using the following script:
<?php
include "cdconnect.php";
?>
<body>
<h1>Enter Design</h1>
<form method="post">
Firstname<input type="text" name="firstname"><br>
Surname:<input type="text" name="surname"><br>
Telephone_no:<input type="text" name="telephone_no"><br>
Emailaddress:<input type="text" name="emailaddress"><br>
<input type="submit">
</form>
<?php
//variables get values from form
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$telephone_no = $_POST['telephone_no'];
$emailaddress = $_POST['emailaddress'];
$query = "INSERT INTO contact_details (firstname,surname,telephone_no,emailaddress)
VALUES
(
'$firstname',
'$surname',
'$telephone_no',
'$emailaddress')";
mysql_query($query) OR die(mysql_error());
if(isset($_POST['firstname']))
{
$firstname = $_POST['firstname'];
}
if(isset($_POST['surname']))
{
$surname = $_POST['surname'];
}
if(isset($_POST['telephone_no']))
{
$telephone_no = $_POST['telephone_no'];
}
if(isset($_POST['emailaddress']))
{
$emailaddress = $_POST['emailaddress'];
}
mysql_CLOSE();
?>
</body>
</html>
I'll be grateful for any assistance. Thanks