Page 1 of 1

Filename to MySql database

Posted: Wed Nov 18, 2009 4:08 am
by flx666
Hello guys.

I am upload 2 files to my server, and I want to save the 2 filenames to my MySQL Database.
I have called them "picname1" and "picname".

How do I do this??? I have tried, with this code - but it will not work.

I dont know if its possible to give the database name a variable like I try???

Please help. :-)

$noFiles = count($_FILES["minfil"]["name"]);
for($i = 0; $i < $noFiles; $i++) {

move_uploaded_file($_FILES["minfil"]["tmp_name"][$i],"upload/" . $_FILES["minfil"]["name"][$i]);
$picName = $_FILES['minfil']['name'][$i];

$sql = "INSERT INTO show_nyheder ('picname[$i]') VALUES('picName[$i]');";
mysql_query($sql);

}

Re: Filename to MySql database

Posted: Wed Nov 18, 2009 4:19 am
by Apollo
flx666 wrote:INSERT INTO show_nyheder ('picname[$i]') VALUES('picName[$i]');
The red part is where the column name should go, not the value (in this case the file name string).

And regarding the value you are using: picName[$i] won't be evaluated in a string, and you're not escaping it to prevent SQL injection (google that!)

Re: Filename to MySql database

Posted: Wed Nov 18, 2009 6:33 am
by flx666
Thanks m8.... :-)