That's It. Thanks! That was exactly what I was looking for. Appreciate
the assist.
-----Original Message-----
From: Mark Carruth [mailto:mcarruth@t...]
Sent: Saturday, December 21, 2002 1:21 PM
To: professional php
Subject: [pro_php] RE: Returning a auto_increment number back to user?
What I think you want is the mysql_insert_id() function.
That will return the value of the primary key field that was generated
by the last insert operation. EG:
Table: id, firstname, lastname
$result = mysql_query("INSERT INTO table VALUES ('', 'John', 'Smith')");
$id = mysql_insert_id();
That will return the primary key field value of the record you just
inserted.
Hope this helps,
Mark Carruth
-----Original Message-----
From: Jim Hankins [mailto:jhankins@o...]
Sent: 21 December 2002 16:08
To: professional php
Subject: [pro_php] Returning a auto_increment number back to user?
Greetings,
I'm a fairly new to php programming, or really programming in general.
I'm trying to figure out how to return what an auto-increment field is
and having trouble doing so. This is a trouble ticket generating system
I'm working on.
At the point of insertion into the database the ticket number is
generated, I want to return the results of that auto-increment number
and echo to the user what it is at the time of processing. Here is the
beginnings of my little script
<?php
// Set Datbase Connections
$db_conn = mysql_connect("localhost:/var/lib/mysql/mysql.sock", "xxxxx",
"xxxxx");
mysql_select_db("opensource", $db_conn);
//Prepare Variables for Database Entry
$Status="Open";
$Priority=3;
$Title=stripslashes($Title);
$ProblemSum=stripslashes($ProblemSum);
//Decide if This is a Valid Customer
$query1 = "select * from Customer where Email='".$Email."'";
$result1 = mysql_query($query1, $db_conn);
$num_results1 = mysql_num_rows($result1);
//Fetch array of customer values from database
$row = mysql_fetch_array($result1);
$CustomerID = ($row["CustomerID"]);
// If Request is coming from a Valid Customer, Continue Processing
Script
if ($num_results1 > 0)
{
$insertquery = "insert into Ticket
(CustomerID, Priority, Status, Title, ProblemSum)
values
('".$CustomerID."', '".$Priority."', '".$Status."',
'".$Title."', '".$ProblemSum."')";
$result2 = mysql_query($insertquery, $db_conn);
// Future point to peform a query to let user know precisely what their
ticket number is <<<<<<<<<<<<<<<<<<<<<<<<<<<<I
assume here is where
somehow I need to either do a new query or perhaps there is a function
that allows me to determine what the value is at time of insertion?
(Since there could be more that one ticket from this user, I'm
struggling to determine how to do a separate query.)
Echo "Success";
exit;
}
// If Customer Email does not exist in Database Echo response and exit
// Attempt to trap this response for further processing
else
{
Echo "UnAuthorized";
exit;
}
?>