I am creating a database using php and viewing the tables in html. Within my coding I scripted an "add/insert" function to insert within the table with a submit button. When the submit button is selected it takes me to the error message listed above. I am not sure what I have changed, I ran this code last night (on a different computer) and all worked fine!?! Anyone have any ideas??
Here is the code for my insert scripts for the TABLE, INSERT info, add.html and insert.php
<?php
$con=mysqli_connect("localhost","root","","Franchise_Call_Log");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create table
$sql="CREATE TABLE caller_info(caller_id int(11) unsigned auto_increment primary key not null,
Firstname varchar(35) not null, Lastname varchar(35) not null,
Franchise varchar(25) not null)";
// Execute query
if (mysqli_query($con,$sql))
{
echo "Table caller_info created successfully";
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
?>
<?php
$con=mysqli_connect("localhost","root","","Franchise_Call_Log");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO caller_info (Firstname, Lastname, franchise)
VALUES ('Peter', 'Griffin',Minneapolis)");
mysqli_query($con,"INSERT INTO caller_info (Firstname, Lastname, Franchise)
VALUES ('Maggie', 'DeJesus',Virginia)");
mysqli_close($con);
?>
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Franchise: <input type="text" name="franchise">
<input type="submit">
</form>
</body>
</html>
<?php
$con=mysqli_connect("localhost","root","","Franchise_Call_Log");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO caller_info (Firstname, Lastname, Franchise)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[franchise]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
*UPDATE I was able to fix the issue above by changing the names of my files but now running everything again I am running into this message:
Notice: Undefined index: Firstname in C:\xampp\htdocs\Final Tests\insert.php on line 11
Notice: Undefined index: Lastname in C:\xampp\htdocs\Final Tests\insert.php on line 11
Notice: Undefined index: Franchise in C:\xampp\htdocs\Final Tests\insert.php on line 11 1 record added
Although its just a notice, when selecting the tables the new record is not there. There is a disconnect somewhere that I am not catching. Any thoughts?