English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I just want a good example to follow of how to use php to add an image name or path to that image into a sql database. I'm using a form that uploads a picture among other things, I upload the image fine to a folder, but I want to add the link to the image into my database, nothing seems to work, help?

2007-03-12 18:00:32 · 3 answers · asked by Daniel B 2 in Computers & Internet Programming & Design

Maybe I'm just to new to this, but how do I get ahold of the file name itself from the form, and add that name into that database, along with the url. So every different row in the database would have the same url except for the filename

2007-03-12 19:29:16 · update #1

i figured it out, i was trying to .$_POST['$filename']. the value, i just took out the $_POST and set the value to $filename, thanks everyone for your help

2007-03-13 10:09:46 · update #2

3 answers

$sqlCommand = "INSERT INTO tblImages SET imagePath='$img_path_here'";
mysql_query($sqlCommand);

2007-03-12 18:02:39 · answer #1 · answered by Rex M 6 · 0 0

I would like to request u to try it yourself. And if u get any problem, then ask. If any one of us provided u the code, u will never learn the thing. I give u some hints.
You will need
enctype="multipart/formdata" in the form tag.
On the file u mentioned in action attribute of form tag, you will be using $_FILES. So try to explore this array first. You can try learning this array at http://www.php.net/features.file-upload.

One thing more,
you don't need to store the url in database. Just store the file name. And have this url in some config.php which u should include in every file. You can use the url from there.
Wish u good luck

2007-03-13 07:50:47 · answer #2 · answered by Atif Majid 3 · 0 1

Something like this?


mysql_connect($server, $user, $pass);
mysql_select_db($dbname);

$sql = "INSERT INTO $table SET path='$path'";
mysql_query($sql);

?>

2007-03-13 01:08:58 · answer #3 · answered by GodBuster 5 · 1 1

fedest.com, questions and answers