I'm really starting to hate PHP

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
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:

$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

// Insert data into mysql
$sql=“INSERT INTO $tbl_name(name, lastname, email)VALUES(’$name’, ‘$lastname’, ‘$email’)”;

// if successfully insert data into database, displays message “Successful”.
echo “Successful”;
echo “
echo “Back to main page”;

else {
echo “ERROR”;

<?php // close connection mysql_close(); ?>[/php]

Ok I figured out what the undefined index problem was with name and lastname, stupid me, I had changed the input names on the input form to test something else and forgot to change them back. DOH!

Sponsor our Newsletter | Privacy Policy | Terms of Service