Jump to content

Why doesn't this code work?


fert

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]
Link to comment
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.
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.