Jump to content

Searching using a database


adamdyer

Recommended Posts

Hey Guys need some help. I got to make it so Customers can search search for a booking that they have placed for a hotel. I done the rest of it I just need to have so the customers search for the booking (using SQL) so that it matches the Customers ID.

 

How do I go about doing this?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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