So I'm trying to add some movies via a form to my database. Here's the form code:
echo "<center>";
echo "Please enter the movie information, following the example below...<br /><br />\n";
echo "<form action = \""; echo $_SERVER["PHP_SELF"];echo "\" method = \"post\" />\n";
for($i = 0; $i < $quantity; $i = $i + 1)
{
echo "Title<br /><input type = \"text\" size = \"50\" value = \"Ocean's Thirteen\" name = \"title[$i]\" /><br />\n";
echo "Director<br /><input type = \"text\" size = \"50\" value = \"Steven Soderbergh\" name = \"director[$i]\" /><br />\n";
echo "Genre<br /><input type = \"text\" size = \"50\" value = \"Thriller, Crime, Comedy\" name = \"genre[$i]\" /><br />\n";
echo "Release Year<br /><input type = \"text\" size = \"50\" value = \"2007\" name = \"year[$i]\" /><br />\n";
echo "Length (minutes)<br /><input type = \"text\" size = \"50\" value = \"122\" name = \"length[$i]\" /><br />\n";
echo "Language<br /><input type = \"text\" size = \"50\" value = \"English\" name = \"language[$i]\" /><br />\n";
echo "Memorable Quote<br /><input type = \"text\" size = \"50\" value = \"You shook Sinatra's hand. You should know better.\" name = \"quote[$i]\" /><br />\n";
echo "Description<br /><textarea rows = \"6\" cols = \"50\" \" name = \"description[$i]\">Danny Ocean again runs the game, so no rough stuff. No one gets hurt. Except for double-crossing Vegas kingpin Willy Bank (Al Pacino). Ocean's crew will hit him where it hurts: in his wallet. On opening night of Bank's posh new casino tower The Bank, every turn of a card and roll of the dice will come up a winner for bettors. And they'll hit him in his pride, making sure the tower doesn't receive a coveted Five Diamond Award. That's just the <i>start</i> of the flimflams. The boys are out to break The Bank. Place your bets!</textarea><br />\n";
echo "Rating (1 is worst, 5 is best)<br /><input type = \"text\" size = \"50\" value = \"5\" name = \"rating[$i]\" /><br />\n";
echo "Available to Borrow<br /><input type = \"text\" size = \"50\" value = \"Yes\" name = \"available[$i]\" /><br />\n";
echo "Property of<br /><input type = \"text\" size = \"24\" value = \"My\" name = \"fname[$i]\" /> <input type = \"text\" size = \"24\" value = \"Name\" name = \"lname[$i]\" /><br /><br />-----<br /><br />\n";
}
echo "<input type = \"hidden\" value = \"$quantity\" name = \"quantity\" />\n";
echo "<input type = \"hidden\" value = \"movieadd\" name = \"action\" />\n";
echo "<input type = \"hidden\" value = \"one\" name = \"auth\" />\n";
echo "<input type = \"submit\" value = \"Add Movie(s)\" />\n";
echo "</form>\n";
echo "</center>\n";
and here's the code for the form processing:
$movie_title = htmlentities($_POST['title']);
$movie_director = htmlentities($_POST['director']);
$movie_genre = htmlentities($_POST['genre']);
$movie_year = htmlentities($_POST['year']);
$movie_length = htmlentities($_POST['length']);
$movie_language = htmlentities($_POST['language']);
$movie_quote = htmlentities($_POST['quote']);
$movie_description = htmlentities($_POST['description']);
$movie_rating = htmlentities($_POST['rating']);
$movie_status = htmlentities($_POST['available']);
$movie_owner_fname = htmlentities($_POST['fname']);
$movie_owner_lname = htmlentities($_POST['lname']);
$quantity = $_POST['quantity'];
echo $movie_director[0];
for($j = 0; $j < $quantity; $j = $j + 1)
{
$count = 0;
if($movie_title[$j] == "") { $count++; }
if($movie_director[$j] == "") { $count++; }
if($movie_genre[$j] == "") { $count++; }
if($movie_year[$j] == "") { $count++; }
if($movie_length[$j] == "") { $count++; }
if($movie_language[$j] == "") { $count++; }
if($movie_quote[$j] == "") { $count++; }
if($movie_description[$j] == "") { $count++; }
if($movie_rating[$j] == "") { $count++; }
if($movie_status[$j] == "") { $count++; }
if($movie_owner_fname[$j] == "") { $count++; }
if($movie_owner_lname[$j] == "") { $count++; }
if($count > 0)
{
die("All fields are required. Go back and fill in the necessary information<br />\n");
}
$property_of = $fname[$j] . " " . $lname[$j];
$query = "INSERT INTO `movies` (`movie_id`, `title`, `director`, `genre`, `released`, `length`, `language`, `quote`, `description`, `rating`, `property_of`, `date_added`, `available`) VALUES ('', '$movie_title[$j]', '$movie_director[$j]', '$movie_genre[$j]', '$movie_year[$j]', '$movie_length[$j]', '$movie_language[$j]', '$movie_quote[$j]', '$movie_description[$j]', '$movie_rating[$j]', '$property_of', NOW(), '$movie_status[$j]')";
$result = mysql_query($query);
if(!$result)
{
die("Could not query the database...");
}
$movies .= $movie_title[$j] . " " . "($movie_year[$j])<br />\n";
}
echo "Successfully added<br /><br />$movies<br />to the database!<br />\n";
exit;
Now, the fields that are hidden are being sent over, but the actual movie information isn't being extracted. Can someone help me out as to why not? Thanks. (When I submit the form I get "All fields are required....etc" where count = 12.