howto get PK id after INSERT??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a form to insert customer data into a table. The form goes to php
page to input data to db hen uses header to go to a final page
displaying customer's information. 
Is there a way to get the ID (custid PK UNIQUE AUTO_INCREMENT) from
mysql after INSERT then pass to final page using urlencode to pull cust
record?

Here is snip from form, post page and final page

FORM CustomerAddNew.php
<snip>
<body onload="document.CustomerAddNew.firstname.focus();">
<form action="CustomerAddNew1.php" method="post" name="CustomerAddNew">
<input type="text" Title="User's first name" name="firstname"
class="txtbox" tabindex="1">
<input type="text" Title="User's last name" name="lastname"
class="txtbox" tabindex="2">
<input type="text" Title="User's address" size="35" name="address"
class="txtbox" tabindex="6">
<input type="text" Title="User's second line of address" size="35"
name="address2" class="txtbox" tabindex="7">
<input type="text" Title="User's city"  name="city" class="txtbox"
tabindex="8">
<select name="State" tabindex="9"> .. </select>
<input name="ziplcode" type="text" class="txtbox" id="zip" tabindex="11"
Title="User's postal/zip code" size="10">
<input name="homephone" type="text" class="txtbox" id="homephone"
tabindex="12" Title="Telephone Number" value="">
<input name="workphone" type="text" class="txtbox" id="workphone"
tabindex="12" Title="Telephone Number" value="">
<input name="otherphone" type="text" class="txtbox" id="otherphone"
tabindex="13" Title="User's Fax Number" value="">
<input name="email" type="text" class="txtbox" id="email" tabindex="14"
Title="User's e-mail address">
</snip>
POST PAGE CustomerAddNew1.php
ini_set('display_errors', 1);
error_reporting(E_ALL &~ E_NOTICE);
// Get information from CustomerAdNew.php and make into functions.
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$home = $_POST['homephone'];
$work = $_POST['workphone'];
$other = $_POST['otherphone'];
$email = $_POST['email'];
// Connect, Select, and POST to database
$connect = mysql_connect("**", "**", "**") or die ("unable to connect to
database" . mysql_error() . "**");
$select = mysql_select_db("**") or die ("unable to connect to database"
. mysql_error() . "**");
$send = mysql_query("INSERT INTO customerinfo (firstname, lastname,
address, address2, city, state, zip, homephone, workphone, otherphone,
email) VALUES ('$firstname', '$lastname', '$address', '$address2',
'$city', '$state', '$zip', '$home', '$work', '$other', '$email')") or
die ("unable to post data" .' ' . mysql_error() . ' '. "to table
custinfo. Please contact your Administrator");
if ($send) {
print '<p> Customer Added </p>';
}
else
{
print 'something went wrong';
}
header("Location: UserMain.php");
</snip>
>From here I would like to populate the page with data that was just
entered. 
(example)
Cust No <? Echo "$custid" ?><br>
Name <? Echo "$firstname" . ' ' . "$lastname" ?><br>
Address <? Echo "$address" ?><br>
Etc . . . 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux