<?php
// open database connection code and then my code as follows
//$id = mysql_insert_id(); << This line wouldn't work ie., $id will be null because there isn't any insert statement before this function call.
//$sql="INSERT INTO clients (clientID, firstname, surname, address1, address2, town, postcode, telephone, email, cardno, expirydate) VALUES ($id,'$_POST[firstname]','$_POST[surname]','$_POST[address1]','$_POST[address2]','$_POST[town]', '$_POST[postcode]','$_POST[telephone]','$_POST[email]','$_POST[cardno]','$_POST[expirydate]')";
//since clientID is an autoincrement field, you don't need to mention it. Use this query instead.
$sql="INSERT INTO clients (firstname, surname, address1, address2, town, postcode, telephone, email, cardno, expirydate) VALUES ('$_POST[firstname]','$_POST[surname]','$_POST[address1]','$_POST[address2]','$_POST[town]', '$_POST[postcode]','$_POST[telephone]','$_POST[email]','$_POST[cardno]','$_POST[expirydate]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$last_insert_client_id = mysql_insert_id();
//get previous insert statement's clientID
//$sql="INSERT INTO bookings (bookingID, clientID, roomID, startdate, enddate, adults, children, roomtype, requirements) VALUES ($id, LAST_INSERT_ID(),'NULL','$_POST[startdate]','$_POST[enddate]','$_POST[adults]','$_POST[children]','$_POST[roomtype]', '$_POST[requirements]')";
$sql="INSERT INTO bookings (clientID, roomID, startdate, enddate, adults, children, roomtype, requirements) VALUES ('$last_insert_client_id','NULL','$_POST[startdate]','$_POST[enddate]','$_POST[adults]','$_POST[children]','$_POST[roomtype]', '$_POST[requirements]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$last_insert_booking_id = mysql_insert_id();
//last insert statement's bookingID
//$result = mysql_query("SELECT * FROM clients WHERE clientID=LAST_INSERT_ID()");
//this also wouldn't work because LAST_INSERT_ID will give you the last inserted id of booking table.. Instead use this
$result = mysql_query("SELECT * FROM clients WHERE clientID='$last_insert_client_id'");
//$result = mysql_query("SELECT * FROM bookings WHERE bookingID=LAST_INSERT_ID()");
//This will work but it will override the value stored in the variable $result. You should use a different variable.
$result1 = mysql_query("SELECT * FROM bookings WHERE bookingID='$last_insert_booking_id'");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>address1</th>
<th>address2</th>
<th>town</th>
<th>postcode</th>
<th>telephone</th>
<th>email</th>
<th>Arrival</th>
<th>Departure</th>
<th>Adults</th>
<th>children</th>
<th>Room Type</th>
<th>Requirements</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['clientID'] . "</td>"; …
nav33n 472 Purple hazed! Team Colleague Featured Poster
HB25 commented: very very helpful +2
nav33n 472 Purple hazed! Team Colleague Featured Poster
theimben commented: Thanks :) +2
Will Gresham commented: Very interesting links +1
peter_budo commented: Nicely done ;) +15
stephen84s commented: Absolutely +6
peter_budo commented: Correct +15
Nick Evan commented: sounds right to me :) +14
Venom Rush commented: Thanks for the help. Really appreciate it ;) +2
Scottmandoo commented: man you help me soo much, thanks. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
wussa commented: thanks wussa +1
praveen_dusari commented: i am learning from u.thank u +1
kevin wood commented: one of the most helpfull people i have come across +1
R0bb0b commented: Hell ya dude! +1
Shanti C commented: smart answer +1
R0bb0b commented: Even works for open office, right on! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
Kavitha Butchi commented: ok, thank you fr ur time. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
Kavitha Butchi commented: thanx a ton , this simple analysis really solved my problem +1
Cobber commented: Fixed my problem +4
nav33n 472 Purple hazed! Team Colleague Featured Poster
OmniX commented: saved me again, thankyou :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
antwan1986 commented: Very useful! +1
kvdd commented: Again he did the job, in the topic: "Show a total in a while". Thanks! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
blufab commented: Rapid responder, with good input +2
maydhyam commented: Great Job.....Thanks :) +1
Nick Evan commented: Good tip on Wamp! +6
sreein1986 commented: Thanx very much 4 ur quick reply +1
scru commented: It's a trade secret. +3
Ezzaral commented: Breakfast of champions :) +9
nav33n 472 Purple hazed! Team Colleague Featured Poster
Kavitha Butchi commented: thankyou fr ur time +1
peter_budo commented: Yes, we do take care of such things ;) +8
kevin wood commented: extremely helpful all the time +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
dottomm commented: Fantastic!!!! +1
OmniX commented: Always helpful as usual :) +1
peter_budo commented: Good work, well done +8
nav33n 472 Purple hazed! Team Colleague Featured Poster
maydhyam commented: This guy definitely knows his stuff... +1
OmniX commented: php guru once again :) +1
tefflox commented: Not even the MySQL.com would help. nav33n is awesome. +2