Question
PHP Program : I received the following error message(below) when I tried to run the insertRecord2.php page. How to fix this error? Notice: Undefined index:
PHP Program: I received the following error message(below) when I tried to run the insertRecord2.php page. How to fix this error?
Notice: Undefined index: fname in C:\xampp\htdocs\PetShop.com\php\insertRecord2.php on line 5 Notice: Undefined index: lname in C:\xampp\htdocs\PetShop.com\php\insertRecord2.php on line 6 Notice: Undefined index: email in C:\xampp\htdocs\PetShop.com\php\insertRecord2.php on line 7 Notice: Undefined index: phone in C:\xampp\htdocs\PetShop.com\php\insertRecord2.php on line 8 Notice: Undefined index: message in C:\xampp\htdocs\PetShop.com\php\insertRecord2.php on line 9
Here is my program.
insertRecord2.php
//connect to the petshop22 database
include "../../db_connect.php";
$first = $_POST['fname'];
$last = $_POST['lname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
//sql insert command
$sql = "
INSERT INTO message(fname, lname, email, phone, message)
VALUES('$first', '$last', '$email', '$phone', '$message')";
//run query and display results
if (mysqli_query($db_connection, $sql)){
echo" New Record created successfully";
}else{
echo "Error: " . $sql . " " . mysqli_error($db_connection);
}
//close the database
mysqli_close($db_connection);
?>
Back to Home
Back to Message Form
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started