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:
Code:
<html>
<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>
Link to rafb for better readability: http://rafb.net/p/1YgTTJ85.html
Here are some pictures describing the situation. The first if of my browser, showing that the list printed is correct. The Items that end up missing from the database are circled in red:
Here is a picture of my console window (MySQL command-line client), showing that the items are indeed missing:
I'm totally baffled by this problem, advice is welcomed
TIA,
Nathan
|