Hi all.
So I'm VERY new to PHP and programming altogether, so my code may be really weird and stuff. I'm trying to make a simple that will update two tables at once. I am having lots of trouble, so if anyone can help, that will be great.
here's the scenario:
I have a site in which I want to list a matrix of hotels and their amenities. The hotel name and hotel ID come from the table "hotels". The amenities, however, come from a table called "hotelAmenities." So far, I was able to produce the matrix page without many problems.
My problem is: in order to add new hotels to these tables, I have an "admin" page where i add all my information. In this page, the hotelID is generated automatically (primary key, auto-increment) on the "hotels" table. Other information is added to this table as well:
here is the query:
$sql = "SELECT hotelID FROM Hotels WHERE hotelID='$hotelID'";
$result = mysql_query($sql)
or die("Couldn't execute query.");
$num = mysql_numrows($result);
if ($num > 0)
{
$message_new = "$hotelID already used. Select another hotel ID.";
include("../admin/somepage.php");
exit();
}
else
{
$sql = "INSERT INTO mttHotels (hotelID,hotelName,hotelDescription,hotelCity)
VALUES ('$hotelID','$hotelName','$hotelDescription','$hotelCity')";
mysql_query($sql);
header("Location: ../admin/somepage.php");
$message_new = "$hotelName was added succesfully.";
}
where the fields are entered into a form on a page. Now...on that same form page, I have about 10 checkboxes. I would like to add the CHECKBOX information to the "hotelAmenities" table. This table has to know the hotelID from the first table (hotels) to know what hotel the amenities belong to. All the querying is done in one file (addnewhotel.php) called by the form. Is there a way to run that first query, retrieve the resulting hotelID, and run a second query to add amenities to the second table??
Thanks for any ideas. And I'm sorry if I have made this terribly difficult to understand.