applebiz89 Posted May 10, 2009 Share Posted May 10, 2009 I was working on my program the other day, and I decided to add in a function to create database and tables, but since then it is telling me that line 64 being the '$pattern = (\.php)' section has an error...but this was fine before If anyone could take a look at my code and see if they can spot anything as to why would be greatly appreciated <?php $dbh = mysql_connect("localhost", "root", "") OR die("Unable to connect to MySQL"); print "Connected to MYSQL<br>"; // create database if (mysql_query("CREATE DATABASE websearcher", $dbh)) { echo "Database created"; } else { echo "Error creating database: "; } // create tables $selected = mysql_select_db("websearcher", $dbh) or die("Could not select websearcher"); $sql_table1 = "CREATE TABLE header ( headerId int NOT NULL AUTO_INCREMENT, fileName varchar(255) NOT NULL, PRIMARY KEY (headerId) )"; if(mysql_query($sql_table1, $dbh)) { print "table 1 created <p>"; } $sql_table2 = "CREATE TABLE vals ( headerFk int NOT NULL, word varchar(255) NOT NULL, PRIMARY KEY (headerFk, word) )"; if(mysql_query($sql_table2,$dbh)) { print "table 2 created <p>"; } function opening($file) { $stoplist = "F:/xampplite/htdocs/worksheets/stoplist.txt" $pattern = "(\.txt$)| (\.php$)"; if(eregi($pattern, $file)){ $file_handle = fopen($file, "r"); $contents = file($file); if(sizeof($contents)>0) { $query_header="INSERT INTO HEADER (filename) values ('$file')"; mysql_query($query_header); //get back header id value $headerId = mysql_insert_id(); } while (!feof($file_handle)){ $data = fgets($file_handle); $words = explode(' ' , $data); $duplicates = array_unique($words); sort($duplicates); if(is_bool(strpos($stoplist, " $duplicates[i] ")) foreach($duplicates as $word) { $word = serialize($word); $sql = "INSERT INTO vals (headerFk, word) VALUES($headerId, '$word')"; if (mysql_query($sql)) { print "successful <p>"; } } } } else { echo "Cant open that file type <p>"; } } function getfiles($dirname=".") { $pattern = "(\.txt$)| (\.php$)| (\.html)| (\.html)"; $file = array($file); if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file) || is_dir($file)) echo "$file <br />"; opening($file); } closedir($handle); } return($file); } getfiles("F:/xampplite/htdocs/worksheets"); mysql_close($dbh); ?> Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/ Share on other sites More sharing options...
corbin Posted May 10, 2009 Share Posted May 10, 2009 I would guess that the $ are causing problems. Try changing from double to single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831079 Share on other sites More sharing options...
applebiz89 Posted May 10, 2009 Author Share Posted May 10, 2009 I just tried it. didn't make a difference. even removed the line to see what happened then the error passed onto the next line...not sure what I have done to it for it to do this. Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831099 Share on other sites More sharing options...
.josh Posted May 10, 2009 Share Posted May 10, 2009 problem is the line before it is missing a ; it helps if you actually post what the error is (or you know, actually read the error). Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831162 Share on other sites More sharing options...
applebiz89 Posted May 10, 2009 Author Share Posted May 10, 2009 yeah I noticed that after I posted it. but theres another problem.. if(is_bool(strpos($stoplist, $duplicates[i])) { foreach($duplicates as $word) { $word = serialize($word); { $sql = "INSERT INTO vals (headerFk, word) VALUES ($headerId, '$word')"; if (mysql_query($sql)) { print "successful <p>"; } } } ?> There error is a parse error. Im not sure why this function isnt working...what I want it to do is to stop words from the stop file going into the database...any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831191 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Missing a closing parenthesis on your first if statement. Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831192 Share on other sites More sharing options...
.josh Posted May 10, 2009 Share Posted May 10, 2009 i count 3 ( in your initial if statement, but only 2 ). Come on man, syntax errors are not exactly rocket science... Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831194 Share on other sites More sharing options...
applebiz89 Posted May 11, 2009 Author Share Posted May 11, 2009 ok...could you point what them errors are? Im only new to php so Im not entirely sure what im looking for if there is a problem thats why I posted on the forum Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831493 Share on other sites More sharing options...
Potatis Posted May 11, 2009 Share Posted May 11, 2009 if(is_bool(strpos($stoplist, $duplicates[i])) should be: if(is_bool(strpos($stoplist, $duplicates[i]))) You were missing a closing bracket, like the last 2 replies said. Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831496 Share on other sites More sharing options...
applebiz89 Posted May 11, 2009 Author Share Posted May 11, 2009 haha cheers. I thought they were talking about '}' s..thats why I was clueless because I couldnt find any Quote Link to comment https://forums.phpfreaks.com/topic/157613-low-priority-spider-file/#findComment-831497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.