Jump to content

Archived

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

slyride

Generate unique id on a form

Recommended Posts

Hello,
I am very new to php and MySql, but I am trying to wade through.
I am trying to modify a form created with php form generator.
I Just want the results page to display the primary key that the new record generated.
Here is a clean snippet (it is actually the whole page.)
My primary key is Invoicenum
[code]<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Date');
pt_register('POST','Customer');
pt_register('POST','Technician');
pt_register('POST','Job');
pt_register('POST','PaymentTerms');
pt_register('POST','DueDate');
pt_register('POST','Qty');
pt_register('POST','Description');
pt_register('POST','UnitPrice');
pt_register('POST','LineTotal');
pt_register('POST','Subtotal');
pt_register('POST','Tax');
pt_register('POST','Shipping');
pt_register('POST','Total');
pt_register('POST','Company');
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="
Date: ".$Date."
Customer: ".$Customer."
Technician: ".$Technician."
Job: ".$Job."
Payment Terms: ".$PaymentTerms."
Due Date: ".$DueDate."
Qty: ".$Qty."
Description: ".$Description."
Unit Price: ".$UnitPrice."
Line Total: ".$LineTotal."
Subtotal: ".$Subtotal."
Tax: ".$Tax."
Shipping: ".$Shipping."
Total: ".$Total."
Company: ".$Company."
";
$message = stripslashes($message);
mail("myemailaddy@mail.com","Form Submitted at your website",$message,"From: phpFormGenerator");
$link = mysql_connect("localhost","username","pass");
mysql_select_db("_invoice",$link);
$query="insert into invoice1 (Date,Customer,Technician,Job,Payment_Terms,Due_Date,Qty,Description,Unit_Price,Line_Total,Subtotal,Tax,Shipping,Total,Company) values ('".$Date."','".$Customer."','".$Technician."','".$Job."','".$PaymentTerms."','".$DueDate."','".$Qty."','".$Description."','".$UnitPrice."','".$LineTotal."','".$Subtotal."','".$Tax."','".$Shipping."','".$Total."','".$Company."')";
mysql_query($query);
?>


<!-- This is the content of the Thank you page, be careful while changing it -->

<h2>Thank you!</h2>

<table width=50%>
<tr><td>Date: </td><td> <?php echo $Date; ?> </td></tr>
<tr><td>Customer: </td><td> <?php echo $Customer; ?> </td></tr>
<tr><td>Technician: </td><td> <?php echo $Technician; ?> </td></tr>
<tr><td>Job: </td><td> <?php echo $Job; ?> </td></tr>
<tr><td>Payment Terms: </td><td> <?php echo $PaymentTerms; ?> </td></tr>
<tr><td>Due Date: </td><td> <?php echo $DueDate; ?> </td></tr>
<tr><td>Qty: </td><td> <?php echo $Qty; ?> </td></tr>
<tr><td>Description: </td><td> <?php echo $Description; ?> </td></tr>
<tr><td>Unit Price: </td><td> <?php echo $UnitPrice; ?> </td></tr>
<tr><td>Line Total: </td><td> <?php echo $LineTotal; ?> </td></tr>
<tr><td>Subtotal: </td><td> <?php echo $Subtotal; ?> </td></tr>
<tr><td>Tax: </td><td> <?php echo $Tax; ?> </td></tr>
<tr><td>Shipping: </td><td> <?php echo $Shipping; ?> </td></tr>
<tr><td>Total: </td><td> <?php echo $Total; ?> </td></tr>
<tr><td>Company: </td><td> <?php echo $Company; ?> </td></tr>
</table>
<!-- Do not change anything below this line -->

<?php
}
?>
[/code]
Thanks
sly

Share this post


Link to post
Share on other sites
Look into mysql_insert_id();

Share this post


Link to post
Share on other sites

×

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.