Bit rough at the moment but I have come up with the following - it doesn't
rename the file using the new ID yet but I am more concerned about my method
for creating the new ID - can anyone see any potential problems such as
database problems, i.e duplicate keys, bad coding practices etc... cheers
matt
if(!empty($_FILES["cr"])) {
$uploaddir = "cr/"; // set this to wherever
//copy the file to some permanent location
if (move_uploaded_file($_FILES["cr"]["tmp_name"], $uploaddir .
$_FILES["cr"]["name"])) {
echo("file uploaded\n");
echo(generateCrId(insertChangeRequest()));
} else {
echo ("error!");
}
}
function insertChangeRequest() {
$sql = mysql_query("INSERT INTO dis_status(status, description)
VALUES('status1', 'status1 description')") or die (mysql_error());
return mysql_insert_id();
}
function generateCrId($key) {
$crId = sprintf("CR-%03d", $key);
return $crId;
}
----- Original Message -----
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "Robert Cummings" <[EMAIL PROTECTED]>
Cc: "Matthew Oatham" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Tuesday, March 23, 2004 12:25 AM
Subject: Re: [PHP] Any Ideas?
> Robert Cummings wrote:
>
> > On Mon, 2004-03-22 at 18:51, Matthew Oatham wrote:
> >
> >>Hi,
> >>
> >>are there any functions that retrieve the last primary key created in
> >>the MySQL table?
> >
> >
> > http://www.php.net/manual/en/function.mysql-insert-id.php
>
> If you read the whole question, though, the poster wanted to use the ID
> in the same query, just in another column. mysql_insert_id() or
> LAST_INSERT_ID() wouldn't help in this case.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php