SkyRanger Posted February 25, 2013 Share Posted February 25, 2013 Can somebody point me in the right direction. I am trying to create a multi file upload script with data stored in database. I can upload single file that is not a problem. But I need to figure out how to upload multiple files. Database is: Description pdfversion picversion zipversion So the user puts in the description then added what ever version they want and it submits into the right column. So the user adds a description then wants to upload a pdf and zip version and when he submits it goes into the right columns and uploads to the directory. Any direction would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/274905-multi-file-upload/ Share on other sites More sharing options...
jazzman1 Posted February 25, 2013 Share Posted February 25, 2013 http://forums.phpfreaks.com/topic/274545-multiple-file-uploads-not-working-properly/ Quote Link to comment https://forums.phpfreaks.com/topic/274905-multi-file-upload/#findComment-1414806 Share on other sites More sharing options...
SkyRanger Posted February 25, 2013 Author Share Posted February 25, 2013 Thanks jazzman. Got it so far to upload the files, but having problems with database entry. Here is the code: $compname=$_POST['icompname']; $ipolicy=$_POST['polnum']; $itofins=$_POST['tofins']; $tstart=$_POST['cstart']; $tend=$_POST['cend']; $client=$_POST['member']; $target = "clients/$client/insurance/"; // use static values in that case $itype1= basename($_FILES['photo']['name'][0]); $itype2= basename($_FILES['photo']['name'][1]); $itype3= basename($_FILES['photo']['name'][2]); if(!empty($_FILES['photo']['tmp_name'])) { // prepare insert query statement $query = "INSERT INTO cinsurh VALUES ('', '$client', '$compname', '$ipolicy', '$itofins', '$tstart', '$tend', '$itype1', '$itype2', '$itype3')"; // Number of uploaded files $num_files = count($_FILES['photo']['tmp_name']); /** loop through the array of files ***/ for($i=0; $i < $num_files;$i++) { // check if there is a file in the array if(!is_uploaded_file($_FILES['photo']['tmp_name'][$i])) { $messages[] = 'No file uploaded'; } else { // move the file to the specified dir if(move_uploaded_file($_FILES['photo']['tmp_name'][$i],$target.'/'.$_FILES['photo']['name'][$i])) { $messages[] = $_FILES['photo']['name'][$i].' uploaded'; } else { // an error message $messages[] = 'Uploading '.$_FILES['photo']['name'][$i].' Failed'; } } } echo '<pre>'.print_r($query, true).'</pre>'; echo '<pre>'.print_r($messages, 1).'</pre>'; // execute query... $result = $mysql->query($query) or die($mysqli->error.__LINE__); } But I am getting this error: Fatal error: Call to a member function query() on a non-object in insert_policy.php on line 61 This is line 61: $result = $mysql->query($query) or die($mysqli->error.__LINE__); Quote Link to comment https://forums.phpfreaks.com/topic/274905-multi-file-upload/#findComment-1414912 Share on other sites More sharing options...
saschaoost Posted February 26, 2013 Share Posted February 26, 2013 Shouldn't that be: $result = mysql_query($query) instead of: $result = $mysql->query($query) Quote Link to comment https://forums.phpfreaks.com/topic/274905-multi-file-upload/#findComment-1414977 Share on other sites More sharing options...
SkyRanger Posted February 26, 2013 Author Share Posted February 26, 2013 (edited) No, but I found the error it is was support to be $result = $mysqli->query($query) saschaoost mysql is depreciated and you should use mysqli now. MySQLi Edited February 26, 2013 by SkyRanger Quote Link to comment https://forums.phpfreaks.com/topic/274905-multi-file-upload/#findComment-1414980 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.