PHP/mySQL and INSERT statements

From: Date: Tue, 28 Aug 2001 06:32:18 +0000
Subject: PHP/mySQL and INSERT statements
Groups: php.db 
Request: Send a blank email to php-db+get-11879@lists.php.net to get a copy of this message
Hello... I'm trying to enter a fair amount of text into a mySQL database from textfiles using PHP. I'm having some problems, and I hope someone can help me. The table looks like this:
Name    : rants
id      : int auto_increment
date    : varchar(8)
category: char(1) title : varchar(75) rtext : text The code I'm using looks like this: if (file_exists($filename)) { // Open it. $file = fopen($filename, "r"); // Skip the first line due to the span tag. $fulltitle = fgets($file, 128); $fulltitle = fgets($file, 128); // Parse out the date from the title. $temp = explode(": ", $fulltitle); $date = $temp[0]; $title = $temp[1]; // Pass over the second span tag. $crap = fgets($file, 128); // Pass over the first line break. $crap = fgets($file, 128); $text = fgets($file, 128); while (!feof($file)) {
     $text = $text.(fgets($file, 128));
} // Replace possibly invalid characters to avoid screwing up the // SQL statement. $title = str_replace("'", "^^singlequote^^", $title); $text = str_replace("'", "^^singlequote^^", $text); $title = str_replace("\"", "^^doublequote^^", $title); $text = str_replace("\"", "^^doublequote^^", $text); // Write out everything that we have. echo "Date: $date<br>\nTitle: $title<br>\nType: $type<br>\nText:<br>\n$text"; $query = "INSERT INTO rants VALUES (1, '$date', '$type', '$title', '$text')"; mysql_db_query($query, $db_link) or die ("<br>Problem!"); } And a typical rant may consist of characters as widely varied as the text in this message (basically a multi-paragraph essay with HTML in it). When I try to execute this, it doesn't add anything into the database, and prints out "Problem!". I have absolutely no idea why. Can someone give me some direction here? I would be eternally grateful for it. I am running PHP4 and mySQL on a Win2K server. Thanks. -Ari _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

« previous php.db (#11879) next »