Php MySQL data entry problem

Reply

Join Date: Dec 2008
Posts: 13
Reputation: johnkhan is an unknown quantity at this point 
Solved Threads: 0
johnkhan johnkhan is offline Offline
Newbie Poster

Php MySQL data entry problem

 
0
  #1
Mar 9th, 2009
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:
  1. <head><title>Movie's</title></head>
  2. <body>
  3.  
  4. <?php
  5. //--------------------- Program Start ----------------------------
  6.  
  7. // Opens file, then sorts contents alphabetically.
  8. $contents = file("./movies.txt");
  9. $nummovies = count($contents);
  10. sort($contents);
  11.  
  12. // Connects to mysql database.
  13. mysql_connect("localhost","root","[password]") or die ("Unable to connect to MySQL server.");
  14. $db = mysql_select_db("god") or die ("Unable to select requested database.");
  15.  
  16. for($i = 0; $i < $nummovies; $i++)
  17. {
  18. $currstr = $contents[$i]; // Get the current string from the array.
  19. echo($i . ': ' . $currstr . '<br>'); // Print the string's array index num, then the string.
  20. $query = "INSERT INTO nathan (movie) VALUES ('$i: $currstr')"; // Insert into table. should look identical to above.
  21. mysql_query($query); // Send the query to MySQL server.
  22. }
  23.  
  24. // Close the connection to the MySQL server.
  25. mysql_close();
  26.  
  27. //--------------------- Program End ------------------------------
  28. ?>
  29.  
  30. </body>
  31. </html>
Last edited by peter_budo; Mar 9th, 2009 at 8:27 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 83
Reputation: ahmksssv is an unknown quantity at this point 
Solved Threads: 7
ahmksssv ahmksssv is offline Offline
Junior Poster in Training

Re: Php MySQL data entry problem

 
0
  #2
Mar 9th, 2009
Originally Posted by johnkhan View Post
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>

Hi....use code tags...

try this below 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>');  
$a=$i . ': '  . $currstr ;                    // Print the string's array index num, then the string. 
$query = "INSERT INTO nathan (movie) VALUES ('$a')"; // Insert into table. should look identical to above.
mysql_query($query) or die(mysql_error());                                // Send the query to MySQL server.
}

// Close the connection to the MySQL server.
mysql_close();            
                                
//--------------------- Program End ------------------------------
?>

</body>
</html>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC