supamastadan Posted September 4, 2008 Share Posted September 4, 2008 Hello. My name is Dan and I have yet another question for all the PHP code gurus out there. What i'm trying to do is write a script to look into a directory filled with text files. Then it will read each file, save the content into a variable and then send that information along with some others into a table on a MySQL database. Here's what I have. <?php //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("funksand_archive"); $dirname = "."; $dh = opendir( $dirname ) or die("couldn't open directory"); while (!(( $file = readdir( $dh ) ) === false ) ) { if ( is_dir( "$dirname/$file" ) ) print ""; $new[] = $file; } foreach($new as $filename){ $fp=fopen($filename, 'r') or die("Cannot Open $file"); while ( ! feof($fp)){ $keywords=fread($fp,filesize($filename)); $date = substr_replace ($filename, "", 10, 4); $type="Rant"; $title="Dan Rant $date"; $number="--"; if($filename!="." && $filename!="..") $result=MYSQL_QUERY("INSERT INTO archive (id,date,type,number,title,keywords)". "VALUES ('NULL', '$date', '$type', '$number', '$title', '$keywords')"); } } ?> It connects just fine (Obviously i didn't include my username and password) and when I have it just print the values instead of query, the pages shows all the conent. The problem I'm having is that despite every other variable entered in, the keywords only seem to happan sparaticly, i.e. out of about 70 text files, only about 17 show up with content in the keywords collum. I'm fairly new at this, so there might be something really obvious that I'm missing, and fread might not even be the right command I want. Any quick way to fix this or should I try something new completely? Thanks ahead of time for you help. Have a good one and take care. - Dan Link to comment https://forums.phpfreaks.com/topic/122793-php-adding-content-of-multiple-files-to-a-mysql-database-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.