last day (15 days later) » 

1:35 PM
0
A: Uploading different unique files to the server and their names saved to the database

RasclattYou have a ton of things messed up, but this should be a working script. Aside from my above comments, I have notated below for additional information and concern: FORM <form id="form1" name="contacts_form" method="post" action="" enctype="multipart/form-data"> <table> <tr> <!...

 
Thank you so much for your patience and your assistance with the code. You explained a lot of things and this very much appreciated. Just one more question, please? This line: ` $sqlArr['columns'][$i] = "photo".$i;` represents the 5 unique filenames. If I have another filename another filename called signSheet, how do I modify this code to include that?
 
So you would have 6 total, 5 called photoX and 1 called signSheet?
 
That's what I thought. I just wanted to clarify. I can't thank you enough for your help and more importantly, the time you took to explain things. I will do better next time as I get better in php.
hi Sorry to trouble you sir. I know this post is closed but I am really having some issues with the code you provided. The code is now able to upload files to the specified folder but the INSERT statement is not working because it gives an error that number of columns specified is not the same as number of VALUES and it has to do with the photox and other fields using the $sqlArr['columns'][$i] = "photo".$i; Can you please help? I am feeling very pressured. Thank you very much
 
Sure. Echo the $sql statement so I can see what it's saying and also write echo '<pre>'; print_r($_POST); print_r($_FILES);echo '</pre>'; Then upload the files and copy the result of this code to your question as an edit so I can see what everything is doing.
 
wow, God bless you. I wasn't even expecting a response. Thank you very much. As you can see, on columns specified, only photo1 is showing. All the other filenames display but photo should be photo1 through photo6 and then SignInSheet and TabSheet. on the VALUES, only the filename selected is displayed. No others is displayed. They all need to display even if they are null. I filled entire form so you can see. I have updated latest code above.
 
1:35 PM
Can you write this before the $sql and copy and paste results after uploading: echo '<pre>'; print_r($_POST); print_r($_FILES);echo '</pre>'; This will show me what is being sent from the form.
 
before the insert statement?
 
Yes, it will print out information from your form when you hit submit. The arrays are important so I can see how to process what you are sending to the script.
 
I have posted the information generated from that.
WOW. which version of the code should I be using now? I see ProcessRequest, ProcessFiles and the original code with connection stuff included.
 
Use the functions to process the files and your post array.
Ok sure. So you need to break your code into pieces, each doing it's own job. So 1) Process the Post variables (or whatever array you want to use for the sql) 2) Check that array is correct and verify it's all the info you want 2) If checks out, then do the file processor. 3) Make a check on that array to make sure it's what you want, 4) If all is good, combine the file (cols,vals) and post (cols,vals) arrays using array_merge() or array_push() 5) Then create your $sql the same way using implode() 6) Verify that the sql was insert properly. That's the workflow.
 
please bear with me a bit. There doesn't appear to be any changes to the original post array and I don't see any reference to the post array on any of the functions. So, it is a bit confusing to me. Many THANKS for your kindness.
 
1:35 PM
No, I haven't revised my original post. Where it says "Will give you something like..." that is the output of the two functions from my EDIT. From that output, there will be two arrays generated-> $sql['post'] and $sql['file']. From there, you need to combine those arrays(the cols and the vals arrays) to generate your final sql statement (from the original post) using array_merge() or array_push().
You could implode() those separately I guess, you wouldn't really need to merge them...now that I think of it. So: $cols = implode(",",$sql['post']['cols']).implode(",",$sql['file']['cols']); and $vals = implode(",",$sql['post']['vals']).implode(",",$sql['file']['vals']);
Ok see final edit. I have assembled the sql statement. There are no checks and validation. That's code you will have to fill in.
 
the problems I am having do not come from selecting everything. It comes from not select everything. I think I erred regrettable if I failed to make this clear at all. Your original solution works great if the users are select all the files (all 9 of them). The problem is that they sometimes select 1 or sometimes select two or there. For some reason, by default, I see BidIDFile which is the first one, then I see photo1. Ideal solution is to show every filename and their VALUES and let the user upload which ever files they wish to.
 
Ok so you need to treat that other file uniquely. See my edits
 
a small good news sir. FINALLY, I am beginning to understand what you are doing. It doesn't appear like I still need original solution you came up with a few days ago. That's clear now. Three things I still need a bit more help on. Please sir, we are almost there. So, please don't give up on me now. 1, Your code appears to in positional notation. In other words, the columns and values in the INSERT statement appear in the order your code is organized. I have post code to show the order of the form fields. 2, The photos start at position 1 instead of 0. Can you please guide me?
 
Ok, I made a couple modifications to the file processor. Now you will get back the sql you are looking for (I think...).
Also the column names have backticks ( ` ) not quotes ( ' ). That is an accepted way to format table and column names...although admittedly, this is a statement I know based on MySQL.
 
in SQL Server, which is what I am using, it is not necessary to use that; as little as I know, I know that much to be true. I don't know what the difference is between this latest change and previous changes. Oh, I keep forgetting to ask about this line: ` // Replace "txt" since that is not what your columns are called` This one is giving me the following error on line 129: Parse error: syntax error, unexpected end of file in ...
 
1:35 PM
Sorry, I think I didn't copy from my editor to this post very well. Try copying the functions again....As for the backticks, they are not necessary in MySQL either, however they are necessary if the name of the column is a reserved word in MySQL, so for instance if you named a column from, you would need a backtick wrapper on it like <backtick>from<backtick>. I just put it as a default.
 
Oh Ok. In my SQL, you use brackets [ ]. You are one of a kind. I can't thank you enough. Testing now...
sorry sir but got this error: Warning: array_filter() expects parameter 1 to be array, string given in... For the next 4 lines starting from this line: ` $_FILES[$name]['name'] = array_filter($_FILES[$name]['name']); $_FILES[$name]['type'] = array_filter($_FILES[$name]['type']); $_FILES[$name]['size'] = array_filter($_FILES[$name]['size']); $_FILES[$name]['tmp_name'] = array_filter($_FILES[$name]['tmp_name']);` My little experience tells me it has to do with rest of filenames to be uploaded.
no other file except the photox is displaying files when selected.
 
Ok I pasted all the new code, so copy it all over (not the original post). Here is a demo: nubersoft.com/client_assets/workboard.php
 
I swear I am beginning to feel guilty and embarrassed bordering you too much. However, I am still getting the same 4 errors. More, I am getting anything for BidIDFile or any of the other files (not fields) I listed at top of screen. For instance, if I select a file to upload for BidIDFile which users must select before selecting photo files, nothing gets displayed. Only when I select photos. None of the other files like SignInSheet or TabSheet are showing when I select those files for upload.
 
Oh sorry, I didn't notice you had two more specific upload entities. Then you need to use the same naming conventions, both form and code ($sql['SignInSheet'] = ProcessFiles('SignInSheet');) as the BidIDFile. So you need to add two new custom named inputs in your form as well like <td class="td_input_form"><input type="file" name="SignInSheet[]"></td>.
 
I can't believe what I am about to say, but can I ask one LAST question? I used the word last in caps because everything looks great. I am able to copy the generated sql insert code and ran it inside sql server management studio and it actually inserted into the database. WoW. So, the last question is how do I actually get it to upload the files to the folder and save the records to the database from php app? You really inspire me with your incredible patience. God has been great to me to allow me run into wonderful people like you. God will reward you abundantly.
 
 
6 hours later…
8:03 PM
@Rasclatt, any idea how to make the code actually insert records to the database?

It is uploading correctly, YEA but I am not sure if I need to do something to make it insert into the database.
 

last day (15 days later) »