Web Hosting Talk







View Full Version : script problem ...


vince2doom
01-06-2006, 09:37 AM
Ive got a script problem with my search script..

error:

http://ring4free.ri.funpic.de/mp3/zoeken.php
(press also search button.)

code:


<center>
<?php

error_reporting(E_ALL);

include("config.php");

$opzoeken = mysql_query("select * from admin");

$controle = mysql_fetch_object($opzoeken);


if($_GET[zoek] != "") { //de grote if

$term = $_GET["s"];

$query2 = mysql_query("SELECT FROM songs WHERE MATCH (artiest,lied) AGAINST ('$term')");

$aantal = mysql_num_rows($query2);

if($aantal == "0") {

echo "<u>Er zijn geen resultaten gevonden.</u>\n";

}

else {

if($controle->opzoeken != "uit") {

$query = mysql_query("SELECT * FROM songs WHERE MATCH (artiest,lied) AGAINST ('$term')");

echo "<u>Er is/zijn <b>$aantal</b> resultaat(en) gevonden.\n";

echo "<table border=\"1\" width=\"700\" cellspacing=\"0\" cellpadding=\"0\">\n";

echo "<tr>\n";

echo "<td width=\"20%\">\nArtiestnaam\n</td>\n";

echo "<td width=\"20%%\">\nSongnaam\n</td>\n";

echo "<td width=\"20%\">\nZoek op\n</td>\n";

echo "</tr>\n";

while($row = mysql_fetch_object($query)){

echo "<tr>\n";

echo "<td width=\"20%\">\n$row->artiest\n</td>\n";

echo "<td width=\"20%\">\n$row->lied\n</td>\n";

echo "<td width=\"20%\">\n<a href=\"http://www.google.com/search?hl=nl&q=$row->artiest+$row->lied\" target=\"_blank\">Zoek info</a>\n</td>\n";

echo "</tr>\n";

}

echo "</table>\n";
}



else {

$query = mysql_query("SELECT * FROM songs WHERE MATCH (artiest,lied) AGAINST ('$term')");

echo "<table border=\"1\" width=\"700\" cellspacing=\"0\" cellpadding=\"0\">\n";

echo "<tr>\n";

echo "<td width=\"20%\">\nArtiestnaam\n</td>\n";

echo "<td width=\"20%%\">\nSongnaam\n</td>\n";

echo "</tr>\n";

while($row = mysql_fetch_object($query)){

echo "<tr>\n";

echo "<td width=\"20%\">\n$row->artiest\n</td>\n";

echo "<td width=\"20%\">\n$row->lied\n</td>\n";

echo "</tr>\n";

}

echo "</table>\n";

echo "<br>\n";

}

}

}

else {

echo "<form method=\"GET\" action=\"zoeken.php\">\n";

echo "zoek liedje op: <input type=\"text\" name=\"s\">\n <input type=\"submit\" value=\"zoek\" name=\"zoek\">\n";

echo "</form>\n";

}

?>
<a href="http://www.php.net" target="_blank"><img src="images/php.gif" border="0"></a>
</center>

Korvan
01-06-2006, 05:10 PM
You need to handle your mysql errors, there are errors in your query (cant tell you exactly what without seeing your database structure)

to find them after you do a query check to see if there is a result set

for example
if(!$query2)
{
echo("line: " . __LINE__ . " Error:" . mysql_error());
//bad query
}

Note in the future you should probably record the errors to a log only you can view instead of to everyone. The less people know about your database the less vunerable it is. While security by obscurity is not the best method, it serves as a first line of defense.

sc_freak
01-09-2006, 02:11 PM
$query2 = mysql_query("SELECT FROM songs WHERE MATCH (artiest,lied) AGAINST ('$term')");
// Select WHAT? from songs? solved warning on line 19


$query = mysql_query("SELECT * FROM songs WHERE MATCH (artiest,lied) AGAINST ('$term')");
// this query is wrong according to the warning, u'd need to see the error mysql is outputting to fix.. do as Korvan say