iceblox Posted July 19, 2007 Share Posted July 19, 2007 Hi Everyone, I got this script and i want to post the name of the file into mysql databse. Im not sure what variable to use. The script allows multiple uploads via a loop which is what is confusing me.. Here is the upload form <? $max_no_img=4; // Maximum number of images value to be set here echo "<form method=post action=addimgck.php enctype='multipart/form-data'>"; echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; for($i=1; $i<=$max_no_img; $i++){ echo "<tr><td>Image $i</td><td> <input type=file name='images[]' class='bginput'></td></tr>"; } echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"; echo "</form> </table>"; ?> Here is the code that deals with the upload <? while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ // this will check if any blank field is entered $filename = $value; // filename stores the value $add = "upimg/$filename"; // upload directory path is set echo $_FILES[images][name][$key]; // uncomment this line if you want to display the file type echo "<br>"; // Display a line break copy($_FILES[images][tmp_name][$key], $add); // upload the file to the server chmod("$add",0777); // set permission to the file. } } ?> And this is script im trying to use to post the file name to my database but im not sure what to replace "name" with.. $result = $db->sql_query("INSERT INTO ".$prefix."_rev_pending (name) VALUES ('".forSql($_POST["name"])."');"); Any help would be appreciated Phil Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 19, 2007 Share Posted July 19, 2007 so you want to add the NAME into the db? try this: $file = $_FILE['images']['name']; $addSQL = "INSERT INTO tbl_name (`id`,`name`)VALUES(NULL,'$file');"; $addQuery = mysql_query($addSQL); if(!$addQuery){ echo "Error with our database"; } else { echo "File name added sucessfully"; } NOT TESTED but whould work. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 19, 2007 Share Posted July 19, 2007 Image[] is an array that hold the file Quote Link to comment Share on other sites More sharing options...
iceblox Posted July 19, 2007 Author Share Posted July 19, 2007 Kool, Its Wotking now! Thanks for your Lewis Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.