Jump to content

selecting a single record set to create an invoice


scotch33

Recommended Posts

Hi,

further to my now resolved question to get a page to write to a new record (http://www.phpfreaks.com/forums/index.php/topic,114253.0.html) I am now further down the line and have hit another wall.

I now want to create an e-mail invoice/receipt from the database to mail to the customer.

At this stage - the customer has paid, they have returned to a 'completed' page on my site where cookies have been called and used to write a new recordset to the database.  The database has a unique id - the invoice number column.

later in this page i need to call that recordset to put the values into a mail.

I know that the recordset will have been created very recently (this code all executes before the page displays so we are about 10lines furtrher on in terms of speed) - so unless there are two visitors doing an order simultaneously calling the most recent record should do the trick, though once i have this sussed i would like to cross ref with the customer surname as a safety measure.

I have found that I need to be using something like - SELECT * FROM dvd_orders WHERE id='$id' - but what i am confused about is how to get $id to be caled as the most recent database record - as it is the database NOT the cookies that sets the ID and thus i don't know what the most recent id will be.

if anyone can help - that would be great.  thanks!
You are risking youself here, if two people register at about the same time, you may select a row that doesnt fit the user.
What you are asking for can be done simply by doing:
SELECT * FROM dvd_orders ORDER BY id DESC LIMIT 1

But I suggest you to add another column to your table containing a random string for example:
$rand_code = md5(rand(1,9999).time().str_shuffle("qwertyuiop12345"));
Then all you have to do is select the column where rand_code=$rand_code

Orio :)
Ok - further to earlier - the random code is causing a problem code (abridged to show relevant bits) is as follows
[quote]
$rand_code = md5(rand(1,9999).time().str_shuffle("qwertyuiop12345"));

$sql_insert = "INSERT INTO dvd_orders SET
cust_name='$cust_name',
cust_surname='$cust_surname',
cust_address1='$cust_address1',
cust_address2='$cust_address2',
cust_town='$cust_town',
cust_county='$cust_county',
cust_postcode='$cust_postcode',
cust_email='$cust_email',
cust_phone='$cust_phone',
unit_quantity='$unit_quantity',
unit_cost='30',
date='$date',
rand_code='$rand_code'
";
if (@mysql_query($sql_insert)) {
    echo "Thanks for your order <br />A receipt has been sent to your e-mail address.";
$result =  mysql_query("SELECT * FROM dvd_orders WHERE rand_code='$rand_code'");
if (!$result) {
exit('<p>error performing query:'.mysql_error().'</p>');
}
[/quote]

this is causing the following error

error performing query:Unknown column 'e34e7916f2cb9609d4433ffe89f7e9b5' in 'where clause'

Archived

This topic is now archived and is closed to further replies.

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