Jump to content

Searching using a database


adamdyer

Recommended Posts

<?php
if(!$_POST[submit]){
echo "<form name=\"this\" action=\"index.php\" method=\"post\">place: <input type=\"text\" name=\"place\">\n";
echo "<input type=\"submit\" value=\"GO GO GO\" name=\"submit\"></form>\n";
}else {
$place = $_POST['place'];

if($place){
	$sql = "SELECT * FROM `tbl` WHERE `place` LIKE '%$place%'";
	$res = mysql_query($sql) or die(mysql_error());
		if(mysql_num_rows($res) == 0){
		echo "no results\n";
		}else {
			while($row = mysql_fetch_assoc($res)){
			echo "place name: $row[place] | some other field: $row[field1]<br>\n";
			}
		}
}else {
echo "omg no place\n";
}
}
?>

 

modify it to your extent

Well, you obviously have some variable (session or cookie) that holds the identifier for the user. All you need to do is perform a simple query using that variable to find out their bookings.

 

Here is an example:

 

<?php

$sql = "SELECT * FROM bookings WHERE customerID='$userID'";
$result = mysql_query($sql)or die(mysql_error());

?>

apparently theres some Syntax error in this code - you couldnt point it out to me , could you ?

 

$sql = "SELECT * FROM Booking Database WHERE Customer_Username='$Customer_Username'";
$result = mysql_query($sql)or die(mysql_error());

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Database WHERE Customer_Username=''' at line 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.