Page 1 of 1
Hotel Booking Form
Posted: Thu Oct 07, 2004 4:15 pm
by alwoodman
OK heres my situation, am creating a database of hotel bookings that i have received on my site. something very simple, at the moment its entering the contents into my HotelBookings Tble and then emailing me the details. i have a BookingID column which is auto incrementing by 1 (ideally would like it to generate a random 8 digit number but can't seem to get it to do it. anyway. so when the new entry hits the db it adds a value of 1 to the db thus creating my BookingID
ideally before it emails me the details i would like it to get the new BookingID from the DB so i have the BookingID when the mail arrives so i can reference the email against the database?
help
Lee
...the code at the moment
Posted: Thu Oct 07, 2004 4:18 pm
by alwoodman
heres a cpy of the code i have already
Code: Select all
$recipient = "info@bookings.co.uk";
$subject = "Booking Enquiry Created for ".$_REQUEST['HotelName'].", ".date("d M, Y : H:n");
$body = "
HotelName: $HotelName \n
Booking ID: $_REQUEST[BookingID] \n // this doesn;t work but maybe something like this?
Prefix: $Prefix \n
Firstname: $FirstName \n
Surname: $Surname \n"
Posted: Fri Oct 08, 2004 2:11 am
by feyd
please use
Code: Select all
tags when posting code.
have a look at [php_man]mysql_insert_id[/php_man].. assuming you are using mysql. As for a "random" 8 digit number, you may need to create your own as the good random generators in php return longer results, or varying length results. You shouldn't use the longer result ones because any substring of 8 digits are quite possible to repeat in a short time later. All the random functions are only pseudo-random generators, so beware.
Now, if you stored all the id's you've ever created in the table, you can make the field "unique", and then you'll get an error when you try to insert a pre-existing one; you will need to analyze the error returned.
set auto increment field
Posted: Fri Oct 08, 2004 2:46 am
by phpScott
the other thing you can do instead of generating a random 8 digit id is to just set your auto_increment field to something like 10000000 then the next insert will be 100000001 and so on.
it will be more predictable but this can be a good and bad thing.
Posted: Fri Oct 08, 2004 3:15 am
by twigletmac
You could use something like [php_man]mt_rand[/php_man]() and set the min and max values to 10,000,000 and 99,999,999 respectively. You would have to check that the number had not been used before of course.
Mac
Posted: Fri Oct 08, 2004 4:21 am
by phpScott
the other thing that you can do is to use the date and clientId or date and room number would provide a reasonable unique number. ie 20041008-11 or something.
the advantage of using the date and some other number is that it would be decipherable just by looking at it.
Posted: Fri Oct 08, 2004 4:32 am
by feyd
wouldn't the wish to have random 8 digits be so it's
not decipherable?

Posted: Fri Oct 08, 2004 5:58 am
by phpScott
depends on what the number is for.
if it is just an order number then something that is decipherable isn't bad.
if is used as a confrimation number of something dealing with personal data that should be kept protected then you are correct.
It sound's like the poster just wanted some way of keeping clients seperate so the poster knew what reservation belonged to whom.
Cheers
Posted: Fri Oct 08, 2004 11:36 am
by alwoodman
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Thanks for the info, i have decided to go with the auto_increment in mysql...seems like the easier option. just havint problems including the BookingID in the email thats generated by the db. any ideas? this is what it looks like now.
Code: Select all
$recipient = "booking@mywebsite.co.uk";
$subject = "Booking Enquiry Created for ".$_REQUEST['HotelName'].", ".date("d M, Y : H:n");
$body = "Booking for: $HotelName \n
Booking ID: $BookingID \n
---Customer Information---
Name: $Prefix $FirstName $Surname
ete etc etc
how would i call that booking ID from the db and then have it included in the email generated? baring in mine it needs to be the last record just created.
cheers for the help
Lee
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Fri Oct 08, 2004 11:39 am
by feyd
Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]
read my first post in this thread.