I'm not very good at MySQL stuff, so I need a little help with a problem I'm having.
I'm trying to make a script that will open up a text file and print the contents of the list onto the screen. Additionally I wanted the contents of the file (a.k.a. what was printed onto the screen) saved as individual rows in a MySQL database.
For the most part this works. But item's #41, #57, and #91 although printed onto the screen, are not entered in the database.
I have absolutely no clue why these three items would not be entered in the table!
Here's the code:
<head><title>Movie's</title></head>
<body>
<?php
//--------------------- Program Start ----------------------------
// Opens file, then sorts contents alphabetically.
$contents = file("./movies.txt");
$nummovies = count($contents);
sort($contents);
// Connects to mysql database.
mysql_connect("localhost","root","[password]") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("god") or die ("Unable to select requested database.");
for($i = 0; $i < $nummovies; $i++)
{
$currstr = $contents[$i]; // Get the current string from the array.
echo($i . ': ' . $currstr . '<br>'); // Print the string's array index num, then the string.
$query = "INSERT INTO nathan (movie) VALUES ('$i: $currstr')"; // Insert into table. should look identical to above.
mysql_query($query); // Send the query to MySQL server.
}
// Close the connection to the MySQL server.
mysql_close();
//--------------------- Program End ------------------------------
?>
</body>
</html>