Ok i have managed to insert customers directly into the database from the form. How can i select the customer id so as to create the invoice for that customer at the same time? I guess this might be simple but i am no mysql expert. IS there a way to select from one table and insert into another?
To be able to create a new invoice at the same time as a new user you would have to create the customer first and then get the customer id to use with the new invoice.
You could do this by saving the customer first then querying the database for something like the customer name to retrieve the new customer record and the customer_id. You could then use this customer_id with your new invoice.
An alternative would be to get the max value of the customer_id column before adding your user. You could then add 1 to this value which would give you the id that the new customer will have when it is created. This method would allow you to create the invoice before the user however it is more prone to errors.
Refer to this tutorial on how to find the fax of the customer_id column:
http://www.tizag.com/mysqlTutorial/mysqlmax.php
I hope this hellps and let me know how you get on.
Matt
No problem, Let me know if you need any help.
Matt
Hi MAtt,
I seem to have it working.
How ever i cannot get the invoice number to go up by 1 each time.
Under the Invoice ( Invoices tab) Under every invoice Id it has "invoice 0"
heres my mysql code
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database. CUSTOMER NOT ADDED TO DATABASE");
$query1="INSERT INTO si_customers (`id`, `domain_id`, `attention`, `name`, `street_address`, `street_address2`, `city`, `state`, `zip_code`, `country`, `phone`, `mobile_phone`, `fax`, `email`, `credit_card_holder_name`, `credit_card_number`, `credit_card_expiry_month`, `credit_card_expiry_year`, `notes`, `custom_field1`, `custom_field2`, `custom_field3`, `custom_field4`, `enabled`) VALUES ('', '1', '', '$name', '$street_address', '$street_address2', '$city', '$state', '$zip_code', '$country', '$phone', '$mobile_phone', '$fax', '$email', '', '', '', '', '$notes', '', '', '', '', '1');";
//mysql_query($query);
$query2="INSERT INTO si_invoices (`customer_id`, `biller_id`, `preference_id`, `date` ) SELECT `id`, `domain_id`, 3, NOW() FROM si_customers;";
mysql_query($query1);
mysql_query($query2);
mysql_close();
do you have an idea on how to do this?
Tahnks Again
The index_id column in the invoices table is does not auto_increment so it won't go up by 1 each time. Try the 'id' field.
Matt
Good to hear you got it sorted.
All the best