Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Php MySQL data entry problem
Old 10-21-2007, 06:36 PM Php MySQL data entry problem
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
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
Nathand is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2007, 06:51 PM Re: Php MySQL data entry problem
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
I forgot to add the text file that the Php script draws from:

Code:
12 angry men 
2001: A Space Odyssey   
25th hour
8 1/2 or Ikiru
A Love Song for Bobby Long
Amelie
American Beauty
American History x
Apocalypse Now 
Artificial Intelligence
Batman Begins
Battle Royale
Big Fish
Blade Runner 
Breakfast Club 
Brick
Butterfly Effect
Calendar girl (1993) 
City of God
Clockwork Orange 
Coach Carter 
Collateral
Contact 
Crash
Dark City 
Dead Man Walking 
Do the Right Thing
Donnie Darko
Elephant 
Eternal Sunshine of The Spotless Mind
Eyes Wide Shut
Fight Club 
Forrest Gump
Freedom Writers 
Garden State
Girl with a Pearl Earring
Good Will Hunting
He Got Game
I Heart Huckabees 
Irreversible
JFK 
Jacob's Ladder 
John Q. 
Jurassic Park
La Vie En Rose 
Life is Beautiful 
Little Children
Little miss sunshine 
Lost in Translation
Magnolia
Mean Girls 
Memento
Million Dollar Baby
Motorcylce Diaries
Mystique River
Now and then
October Sky 
One Flew Over the Cuckoo's Nest 
Princess 
Pulp Fiction
Requiem for a Dream
Revolver 
Romeo & Juliet (1996 version)
Royal Tenenbaums 
SLC Punk
Saved!
Scarecrow 
Schindlers List
Seven 
Sliver
Snatch 
Snow Falling On Cedars 
Solaris (original)
Stand By Me 
Straw Dogs
Taxi Driver 
The Color Purple
The Deer Hunter 
The Game 
The Hours 
The Matrix
The Pursuit of Happyness 
The Shape of Things 
The Shawshank Redemption
The Suicide Virgins
The Talented Mr. Ripley
The beach
The green mile
To Kill A Mockingbird 
V For Vendetta
Volver 
What's Eating Gilbert Grape 
Wild Strawberries
Zodiac
If you save that as movies.txt in the same directory as the code above, you will get the same problem as me. Unless the problem is my machine
Nathand is offline
Reply With Quote
View Public Profile
 
Old 10-21-2007, 07:28 PM Re: Php MySQL data entry problem
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Your apostrophes are causing the problem as these are special characters.

You need to do some escaping

$currstr = (!get_magic_quotes_gpc()) ? addslashes($contents[$i]) : $contents[$i];
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 10-22-2007, 11:10 AM Re: Php MySQL data entry problem
Inet411's Avatar
Skilled Talker

Posts: 88
Name: programmer
Location: internet
Trades: 0
Quote:
Originally Posted by maxxximus View Post
Your apostrophes are causing the problem as these are special characters.

You need to do some escaping

$currstr = (!get_magic_quotes_gpc()) ? addslashes($contents[$i]) : $contents[$i];
Maxxximum is exactly correct. I had a similiar issue just yesterday and had to addslashes and viola all was well.
Inet411 is offline
Reply With Quote
View Public Profile Visit Inet411's homepage!
 
Old 10-22-2007, 11:11 AM Re: Php MySQL data entry problem
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
Thanks guys. Works perfectly now!!

Thanks again,
Nathan
Nathand is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php MySQL data entry problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21131 seconds with 12 queries