Jump to content

[low priority] 'spider' file


applebiz89

Recommended Posts

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);

?>

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.