I’m starting to lose my patience with all of this, here is a simple script to upload user input from a form to MySQL.
I have 3 inputs fields, name, lastname, and email,
Simple, right? you would think so but the form submission worked fine the first couple times now it submits the form data to the database but gives me the following errors:
Notice: Undefined index: name in C:\xampp\htdocs\trial\insert1.php on line 14
Notice: Undefined index: lastname in C:\xampp\htdocs\trial\insert1.php on line 15
Successful
Back to main page
I’ve defined the index “name” and “lastname” but I continue to get this error and it’s really pissing me off!
Here is the code:
[php]<?php
$host=“localhost”; // Host name
$username=“root”; // Mysql username
$password=“xxxx”; // Mysql password
$db_name=“trial”; // Database name
$tbl_name=“uploads2”; // Table name
// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);
// Get values from form
$name=$_POST[‘name’];
$lastname=$_POST[‘lastname’];
$email=$_POST[‘email’];
// Insert data into mysql
$sql=“INSERT INTO $tbl_name(name, lastname, email)VALUES(’$name’, ‘$lastname’, ‘$email’)”;
$result=mysql_query($sql);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;
echo “Back to main page”;
}
else {
echo “ERROR”;
}
?>