adamdyer Posted August 23, 2007 Share Posted August 23, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/66395-searching-using-a-database/ Share on other sites More sharing options...
marcus Posted August 23, 2007 Share Posted August 23, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/66395-searching-using-a-database/#findComment-332294 Share on other sites More sharing options...
pocobueno1388 Posted August 23, 2007 Share Posted August 23, 2007 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66395-searching-using-a-database/#findComment-332296 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66395-searching-using-a-database/#findComment-332314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.