|
Posted by Mike P2 on 05/04/07 22:32
On May 4, 4:01 pm, m...@londonstudent.co.uk wrote:
> Does anyone know how I can change this form to get it to do what I
> need?
>
> Thanks for any help
>
> Matt
You have to move the uploaded file after you insert whatever it is you
insert into the database so you can get the new ID number. The most
efficient way of retrieving this incremented ID depends on how you are
connecting to MySQL. If you are using the regular MySQL interface, you
can get the ID number back out by using the mysql_insert_id() function
immediately after your INSERT statement. If you are using MySQLi (non-
procedural version), you can use $MySQLiObj->insert_id.
Also, when dealing with uploaded files, for security reasons it's
usually best to use the move_uploaded_file() function instead of
copy(). But you may already be checking the uploaded file using
is_uploaded_file(). move_uploaded_file() just does both at once.
So here's an idea of what should work:
<?php
//...validation, DB connection, etc...
if( !$db->query( "INSERT INTO `it` ( `...`, `...` ) VALUES ( '...',
'...' )" ) )
{
$uhOh = "Query failed: $db->error";
}
else if( !move_uploaded_file( $_FILES['PhotoUpload']['tmp_name'],
"directory/pictures/$db->insert_id.bmp" ) )
{
$uhOh = 'Could not move uploaded file';
}
//...
?>
-Mike PII
Navigation:
[Reply to this message]
|