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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!