Jump to content

Archived

This topic is now archived and is closed to further replies.

fert

Why doesn't this code work?

Recommended Posts

this code is a search code that has the names of webpages in a database, opens them, reads them and looks for the search phrase in each, but it doesn't work can anybody tell me why?
[code]
<html>
<head>
<title>Search</title>
</head>

<body bgcolor="#999900">
<h1>Search results</h1>
<?php
$cn=@mysql_query("host","username","password") or die(mysql_error());
@mysql_select_db("db_name",$cn) or die(mysql_error());

$name="page";
$files;

$result=@mysql_query("SELECT * FROM search_pages",$cn) or die(mysql_error());
$num=mysql_num_fields($result);

while($row=mysql_fetch_array($result));

for($count=1;$count<$num;$count++)
{
$name.=$count;

$file=@fopen($row[$name],"r") or die("Cannot open file");
$text=@fread($file,filesize($row[$name])) or die("Cannot read file");

if(stristr($text,$_POST[search]))
{
$files[$count]=$row[$name];
}
else
{
$files[$count]="";
}

@fclose($file);
$name="page";
}

for($count=1;$count<$num;$count++)
{
if($files[$count]!="")
{
echo "<p><a href=\"http://www.mysite.net".$files[$count]."\">{$count}</a></p>";
}
}
?>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
The database connection should be

[code]$cn=@mysql_connect("host","username","password") or die(mysql_error());[/code]

where host, username and password are replaced with the appropriate values for your database.

Regarding fetching the data, are you expecting to get several rows of data, or just a single row with many fields?  Your code looks like it expects a single row with many fields.

Share this post


Link to post
Share on other sites
[quote author=btherl link=topic=112894.msg458421#msg458421 date=1161922379]
The database connection should be

[code]$cn=@mysql_connect("host","username","password") or die(mysql_error());[/code]

[/quote]
Thanks now it works

Share this post


Link to post
Share on other sites

×

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.