[SOLVED] My search script doesn't work!
Posted: Fri Sep 03, 2004 7:49 am
feyd | Please use
I have added an echo statement on the select line and have tested the select line in mysql where it works fine.
I have a feeling it is something obvious I am missing
but would be grateful for any advice. The script is as follows:
Thanks for looking! 
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hello all.
I am on day 3 of learning how to use mysql/php and have written the script below.
Unfortunately it doesn't work!
Where I enter attributes where a return is expected I get the messageCode: Select all
You have an error in your SQL syntax near '' at line 12I have a feeling it is something obvious I am missing
Code: Select all
<html>
<head>
<title>PubSearch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="get" action="pubsearch.php">
<p><font color="#000000" face="Arial, Helvetica, sans-serif">First part of post
code (eg GL1):
<input name="pc1" type="text" size="5" maxlength="4">
</font></p>
<p><font color="#000000" face="Arial, Helvetica, sans-serif">Second part:
<input name="pc2" type="text" size="3" maxlength="1">
</font></p>
<p> <font color="#000000" face="Arial, Helvetica, sans-serif"> Type of Venue:
<select name="ven">
<option>Pub</option>
<option>Resturaunt</option>
<option>Night Club</option>
<option>Taxi</option>
</select>
</font></p>
<p><font color="#000000" face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Submit">
</font></p>
</form>
<?php
$var = @$_GET['pc1'] ;
$a = addslashes(trim($var));
$var = @$_GET['pc2'] ;
$b = addslashes(trim($var));
$var = @$_GET['ven'] ;
$c = addslashes(trim($var));
mysql_connect("localhost","","");
mysql_select_db("pubs") or die("Unable to select database");
$query = "SELECT
DISTINCT location.postalcode,
location.postal,
venue.VenueType,
venue.Name
FROM
location LEFT JOIN venue
ON location.RegionCode = venue.RegionCode
WHERE
location.postalcode = '$a' AND
location.postal = '$b' AND
venue.VenueType = '$c'"; echo $query;
$numresults = mysql_query($query);
$numrows = mysql_num_rows($numresults);
if ($numrows == 0) {
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $a. $b .$c. "" returned zero results</p>";
} else {
if (empty($s)) {
$s=0;
}
$query .= " limit $s,$limit";
$result = mysql_query($query) or die(mysql_error());
echo "<p>You searched for: "" . $var . ""</p>";
echo "Results";
$count = 1 + $s ;
while ($row= mysql_fetch_array($result)) {
$title = $row["name"];
echo "$count.) $title" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
}
?>
</body>
</html>feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]