PHP Search Page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kslagdive
Forum Newbie
Posts: 3
Joined: Mon Sep 29, 2008 1:17 pm

PHP Search Page

Post by kslagdive »

hi friends,
I am working on Search code where it finds inserted keyword across our pages.
i am facing problem when inserting search pages in the database. because when
page contains only text then it is executing. but when image on page it is not executing.
Please, anyone help me regarding this.
thanks,
kashinath lagdive
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: PHP Search Page

Post by The_Anomaly »

You might want to give us more info/code. The fact that something "doesn't execute" when you "insert it into a database," isn't nearly enough information.
kslagdive
Forum Newbie
Posts: 3
Joined: Mon Sep 29, 2008 1:17 pm

Re: PHP Search Page

Post by kslagdive »

thanks,
here i am searching specific keyword across no of file in dir.
code is for searching all contents of files and insert it into database so that we
retrieve information matching those page title and some content description on result page.
code is like this
------------------------------------------------------------------------
<?php
$con = mysql_connect("localhost","root","");

mysql_select_db("mydata");

$delimiter = '/';

if($con!=null)
{

function parseCodeTree($path) {

global $delimiter;

if ($dir = opendir($path)) {

while ($item = readdir($dir)) {


if (is_dir($path.$delimiter.$item) && $item != "." && $item != "..") {


parseCodeTree($path.$delimiter.$item);


} elseif ($item != "." && $item != "..") {



$scriptTitle = str_replace(".php", "", $item);
$scriptTitle = str_replace("_", " ", $scriptTitle);

echo '------->'.''.$scriptTitle;


$scriptContents = file_get_contents($path.$delimiter.$item);

echo $scriptContents;


// Insert the file information into database
$query = "INSERT INTO searchtab VALUES('000', '$scriptTitle' , '$scriptContents')";
$result = mysql_query($query);

echo '<br>here is result------->'.''.$result;
}
}
closedir($dir);
}
return 1;
}

parseCodeTree('myPHP');
}
else
{
echo 'not connected';
}
?>
-----------------------------------------------------------------------
now this code executing means successfully loading database properly when only text on our pages.
image containing page is not properly inserting. So, Please help me regarding this.
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: PHP Search Page

Post by The_Anomaly »

Try editing that post, adding indentation, and using the code tags. Will be much easier to understand.

Without giving myself the headache of trying to comprehend it, what I think of offhand may have to do with your lack of escaping. If only text works, perhaps the presence of the HTML img tags and the paths contained there in is not being escaped properly and screwing up your code.

In any case, you probably should still be escaping it anyway.

In addition, I'm almost certain that there's a better way of making a PHP Search Engine for your site. It's such a common problem, there must be a myriad solutions for it. Do some googling. In just 10 seconds, I already found one, although I'm sure there are many others.
kslagdive
Forum Newbie
Posts: 3
Joined: Mon Sep 29, 2008 1:17 pm

Re: PHP Search Page

Post by kslagdive »

thank you Mr. Thomas sir,
i am working on your search link.
Post Reply