| | |
Php MySQL data entry problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 13
Reputation:
Solved Threads: 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:
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:
php Syntax (Toggle Plain Text)
<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>
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.
•
•
Join Date: Feb 2009
Posts: 83
Reputation:
Solved Threads: 7
•
•
•
•
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>![]() |
Similar Threads
- Populating form with existing MySQL data (PHP)
- javascript: addContent - Packaging Options (JavaScript / DHTML / AJAX)
- Importing data from one database to another (PHP)
- JSP database connectivity according to Model View Controller (MVC) Model 2 (JSP)
- php.ini confusion (PHP)
- help with menu selection based from other menu showing "selected" entry from db (PHP)
- updating multiple columns in multiple rows (PHP)
- Problem with inserting data into mysql with PHP (PHP)
- php mysqp delete problem (PHP)
- Recent CS grad - indecisive.... (IT Professionals' Lounge)
Other Threads in the PHP Forum
- Previous Thread: Wget in PHP
- Next Thread: echo out email field to browser.
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access action address ajax apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date directory display domain download dynamic echo email error errorlog file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link load login loop mail masterthesis menu mlm mod_rewrite multiple mysql oop paypal pdf php popup problem query radio random record recursion regex remote script search security server sessions sms soap source space sql syntax system table tutorial update upload url validation validator variable video web xml youtube





