I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:
INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");
INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");
INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
Good food.", " (Minnie Mouse - 01/03/2004)");
etc etc
These have been parsed from a review form that a client already
submitted. What I need to do now after I have reviewed the information
for appropriateness and grammer is to insert it into my MySQL database.
I would write single line entries like this:
// Set Mysql Variables
$host = "localhost" ;
$user = "root";
$pass = "";
$db = "rest";
$table = "reviews";
// Connect to Mysql, select the correct database, and run the query
which adds the data gathered from the file into the database
mysql_connect($ host,$user,$pas s) or die(mysql_error ());
mysql_select_db ($db) or die(mysql_error ());
$add_review = "INSERT INTO $table
values('','$rna me','$umeal','$ ucomment','$una me')";
mysql_query($ad d_all) or die(mysql_error ());
But how would I write the $add_review to read each line of the
add2db.txt and enter it as a separate entry?
already entered on separate lines in the following form:
INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");
INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");
INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
Good food.", " (Minnie Mouse - 01/03/2004)");
etc etc
These have been parsed from a review form that a client already
submitted. What I need to do now after I have reviewed the information
for appropriateness and grammer is to insert it into my MySQL database.
I would write single line entries like this:
// Set Mysql Variables
$host = "localhost" ;
$user = "root";
$pass = "";
$db = "rest";
$table = "reviews";
// Connect to Mysql, select the correct database, and run the query
which adds the data gathered from the file into the database
mysql_connect($ host,$user,$pas s) or die(mysql_error ());
mysql_select_db ($db) or die(mysql_error ());
$add_review = "INSERT INTO $table
values('','$rna me','$umeal','$ ucomment','$una me')";
mysql_query($ad d_all) or die(mysql_error ());
But how would I write the $add_review to read each line of the
add2db.txt and enter it as a separate entry?
Comment