Page 1 of 1

PHP Conundrum

Posted: Tue Jun 06, 2006 12:28 pm
by neko-kun
Hi there.
I just started PHP a week ago. :D Was wondering, if some of you could answer this question.

The Idea
The page I am making gives information on products. Each product has it’s own folder named after it’s database ID number. In this folder are files that belong to the product.

How it works
On the main page you can add a new product. You give it a name and the PHP gives it an ID number. Then there is a big fat button that links them back to the main page. There they have to search for the product. Once they access the product's edit page they have to hit another big button that creates new directories and uploads files to that directory before they can edit the product's page.

Ideally
As you can see it is not very user-friendly.
Ideally the user hits the submit button on the create new product page and the script automatically creates the folders and uploads the files. The thing is, the script dose not know the ID number of the product yet.


Uploads new product to database (the folowing is only an example)

Code: Select all

<?
$Name=$_POST['new_product];
.
.
.
$addProduct = "INSERT INTO Product (Name) VALUES ('".$Name."')";
$result = mysql_query($addProduct);
?>
Now the person goes back. Searches for the product. Opens up the product’s edit page which has the product ID hidden in it. The user has to press a button. This then sends the product ID to the following code.

Creating dir and upload files (the folowing is only an example)

Code: Select all

<?
$input=$_POST['productID'];

mkdir("Product/".$input."/", 0700);
mkdir("Product/".$input."/Images/", 0700);

$file = 'AAA/BBB/CCC.xxx';
$newfile = 'DDD'.$input.'/CCC.xxx';

if (!copy($file, $newfile)) {
   echo "failed to copy $file...\n";
}
?>
Is there a way to combine these codes?

Posted: Tue Jun 06, 2006 3:52 pm
by AS_Platinum

Code: Select all

mysql_insert_id();
is what your after if i'm reading what your saying correctly, declare $input=mysql_insert_id(); after your insert statement.

HTH

Posted: Tue Jun 06, 2006 6:34 pm
by neko-kun
Great it worked.
Thanks for your help.
It’s so much better now.