Filename to MySql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flx666
Forum Newbie
Posts: 6
Joined: Tue Nov 17, 2009 1:48 pm

Filename to MySql database

Post 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);

}
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Filename to MySql database

Post 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!)
flx666
Forum Newbie
Posts: 6
Joined: Tue Nov 17, 2009 1:48 pm

Re: Filename to MySql database

Post by flx666 »

Thanks m8.... :-)
Post Reply