Forum Moderators: coopster

Message Too Old, No Replies

HELP.simple php script searching mysql database table

searching mysql for list of results

         

steveinmyrtle

3:05 am on Nov 8, 2005 (gmt 0)

10+ Year Member



I am trying to fix up this script so it will search fields which are entered into a database. I want the users to be able to enter text or select from a drop down list and be able to pull up what they are looking for if it has been entered in the database. So far what I have is below. My script for adding enteries to db works fine.

when you submit
Hotel: Crown Reef
Myrtle Beach Area: North Strand
it gives you this on the ouraction.php page
select * from hotels where value=crown reef and value='north strand'
----------------------------
-----html for search------
----------------------------
<html>
<head>
<title>Search Hotels</title>
</head>
<body>
<form name="form1" method="POST" action="ouraction.php">
<p> Hotel Name: <input name="name" type="text" id="name"><p>
<SELECT NAME="myrtlebeacharea">
<OPTION VALUE="ns">North Strand
<OPTION VALUE="mb">Myrtle Beach
<OPTION VALUE="ss">South Strand
</SELECT>
<SELECT NAME="city">
<OPTION VALUE="cherygrove">Cherry Grove
<OPTION VALUE="northmb">North Myrtle Beach
<OPTION VALUE="myrtlebeach">Myrtle Beach
<OPTION VALUE="surfside">Surfside Beach
<OPTION VALUE="gardencity">Garden City
</SELECT>
<p><input type="submit" name="submit" value="submit">
</form>
</body>
</html>

--------------------------------------
------php script to search----------
--------------------------------------

<?
$host = "mysql-host";
$user = "mysql-username";
$pass = "mysql-password";
$dbname = "hotellist";

$connection = mysql_connect(mysql-host,mysql-username,mysql-password) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$sql = "select * from hotels where id=" . $_POST['name'] . " and id='" . $_POST['myrtlebeacharea'] . "'";
echo $sql;

$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['name'],": ",$row['myrtlebeacharea'];
}

?>

--------------------------------------------
I would like to add more fields to like
$_POST['address']
$_POST['city']
$_POST['website']

etc....

any help with this would be appreciated thanks

Steve

[edited by: coopster at 2:52 pm (utc) on Nov. 8, 2005]
[edit reason] removed unnecessary code and urls [/edit]

jatar_k

10:03 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld steveinmyrtle,

you could start with this thread about Developing a MySQL search query [webmasterworld.com] from our PHP library [webmasterworld.com].

see if that gives some explanation and then we can go from there.