Undefined Index

Sorry if I’m posting incorrectly. My php code is erroring out when I preview it. There is a html form that users fill out to join my Movies collection for rental. Kinda like netflix. Upon submission their name, membership info is listed in my database. Let me know if you need to see the html code.

Here are the errors:
Notice: Undefined index: fname in D:\web\mymovies.php on line 24

Notice: Undefined index: lname in D:\web\mymovies.php on line 25

Notice: Undefined index: email in D:\web\mymovies.php on line 26

Notice: Undefined index: membership in D:\web\mymovies.php on line 27
statement is INSERT INTO user (fname, lname, email, membership, myid) VALUES(’’, ‘’, ‘’, ‘’, ‘myname’)
You are registered as a level member.
Use your to log into the site on future visits.SQL error during query: No database selected

Here is my php:

<?php (Line 15) //Establish the database connection for the user $con = mysql_connect("myconnection", "user", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } (Line 20) //Select the database to connect to mysql_select_db("movies", $con); //Get form data values $first = $_POST["fname"]; (Line 25) $last = $_POST["lname"]; $email = $_POST["email"]; $membership = $_POST["membership"]; (Line 30) //Insert data into user table $insert = "INSERT INTO user (fname, lname, email, membership, id) VALUES('$first', '$last', '$email', '$membership', 'myid')"; print "statement is $insert
"; $results = mysql_query($insert); (Line 35) //Test the fields if(IsSet($first) && strlen ($first)>0 && IsSet($last) && strlen ($last)>0&& IsSet($email) && strlen ($email)>0) (Line 40) print "Welcome to MyMovies $first $last !
"; print "You are registered as a $membership level member.
"; print "Use your $email to log into the site on future visits."; (Line 45) if(!$results) { die("SQL error during query: " . mysql_error()); print "Please return to the previous page to complete your data.
"; } ?>

Hi!

PHP is telling you the $_POST array doesn’t contain the items fname,lname,email,membership

Make sure the “method” attribute of the form is set to “post”.
Also make sure the “name” attributes of your form inputs match the $_POST array indexes you’re trying to read; this needs to be done because the names of your input fields are turned into $_POST indexes.

Feel free to also post the html if you need more help.

Cheers!

Sponsor our Newsletter | Privacy Policy | Terms of Service