Jump to content


Photo

Why doesn't this code work?


  • Please log in to reply
2 replies to this topic

#1 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 27 October 2006 - 04:01 AM

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?
<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>


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 27 October 2006 - 04:12 AM

The database connection should be

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

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.

#3 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 27 October 2006 - 07:17 AM

The database connection should be

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

Thanks now it works

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users