I am pulling my hair out...

I know that the answer to this is obvious, but i can't for the life of me see it.

I have a table called order_seq which is essentially a table merley to substitute for a sequence.

It's purpose is simply to provide me with invoice numbers. all i want to do is increase the auto-increment and the return the value with last_insert_id() and then use that number to insert into another table.

here is my code

// increase the sequence with an insert
$incrId= mysql_query("INSERT INTO order_seq (order_id) VALUES (0)");

// get the sequence number and echo it.

$get_invoice_id = mysql_query("SELECT distinct last_insert_id() FROM order_seq as invoiceID");
while ($row = mysql_fetch_array($get_invoice_id, MYSQL_ASSOC))
{
echo $row["invoiceID"];
}

the error i am getting is:

Notice: Undefined index: invoiceID

any help appreciated...

cheers,
Mitch.

    Try

    $get_invoice_id = mysql_query("SELECT distinct last_insert_id() as invoiceID FROM order_seq"); 
    

    but...

    couldn't you just do

    $incrId= mysql_query("INSERT INTO order_seq (order_id) VALUES (0)");
    $myID = mysql_insert_id();
    

      yep just found out about mysql_insert_id();

      $incrId= mysql_query("INSERT INTO order_seq (order_id) VALUES (0)");
      $invoice_id = mysql_insert_id();

      many thanks.

      Mitch.

        Write a Reply...