Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code uploads to the server but not inserting to the database

Status
Not open for further replies.

Kaylech

Programmer
Mar 12, 2015
29
US
Greetings mates,

I have working on this code since this morning and it has stumped me.

I have the code that is supposed to upload one or more files at same time to the database as well as insert the accompanying records to the database.

The upload part works for the most part.

Here are the issues I have not been able to resolve so far.

1, When I debug the code, the files that get submitted to the database are blank.
Please see the INSERT statement generated from echo statement:
Code:
INSERT INTO bids (BidDate,DueDate,DueTime,BidTitle,BidID,Description,
'BidIDFile','Addend1','SignInSheet','TabSheet'
,Department,Xcontract,
ContactEmail,ContactPhone,NumofBids,AwardDate,
AwardRecip1,BidType,LastUpdate,Notes,BidStatus)
VALUES ('03/27/2015', '03/28/2015','2:00pm',Testing','T8877',
'Testing again','', '','','','','','','','','','',')

NOTE: I intentionally left the fieldnames blank. Those are populating correctly.

2, As stated, no records are getting submitted to the database.

3, Lastly, I can only get one file to upload at a time. We would like our users to have the ability to submit as many of the those files as possible.

Your input is greatly appreciated.
Some additional relevant code:

Code:
            //start creating Addend from position 1 instead of position 0. e.g: Addend1,... Addend6
            $sqlArr['values'][$i += 1]   =   "'".ms_escape_string($_FILES['item']['name'][$i])."'";
            $sqlArr['columns'][]  =   "BidIDFile";
            $sqlArr['columns'][$i]  =   "Addend".$i;
            $sqlArr['columns'][]  =   "SignInSheet";

if(isset($sqlArr['columns'])) {
    $sql="INSERT INTO bids (BidDate,DueDate,DueTime,BidTitle,BidID,Description,,'".implode("','",$sqlArr['columns'])."',Department,Xcontract,ContactEmail,ContactPhone,NumofBids,AwardDate,AwardRecip1,BidType,LastUpdate,Notes,BidStatus)
              VALUES ('$bidDate', '$dueDate','$dueTime',$bidTitle','$bidId','$desc',".implode(",",$sqlArr['values']).", '$dept','$bidContact','$contactEmail','$contactPhone','$numBids','$awardDate','$awardrecip1','$bidType','$lastUpdate','$notes',$status')" ;
    $objQuery = sqlsrv_query($conn, $sql);
    sqlsrv_close($conn);
} ?>

Thanks in advance for your help
 
Your have a few values missing an apostrophe $bidTitle and $status don't know if they are string or not.

PHP:
$sql="INSERT INTO bids (BidDate,DueDate,DueTime,BidTitle,BidID,Description,,'".implode("','",$sqlArr['columns'])."',Department,Xcontract,ContactEmail,ContactPhone,NumofBids,AwardDate,AwardRecip1,BidType,LastUpdate,Notes,BidStatus)
              VALUES ('$bidDate', '$dueDate','$dueTime',$bidTitle','$bidId','$desc',".implode(",",$sqlArr['values']).", '$dept','$bidContact','$contactEmail','$contactPhone','$numBids','$awardDate','$awardrecip1','$bidType','$lastUpdate','$notes',$status')" ;

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
Oh and you also have 2 commas together in your field list.

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
Thanks Jim,

I think that a major part of the problem is here:

Code:
INSERT INTO bids (BidDate,DueDate,DueTime,BidTitle,BidID,Description,'BidIDFile','Addend1','SignInSheet','TabSheet',Department,Xcontract,ContactEmail,ContactPhone,NumofBids,AwardDate,AwardRecip1,BidType,LastUpdate,Notes,BidStatus) VALUES ('03/27/2015', '03/27/2015','2:00pm',Test','7777','Test','', '','','','','','','','','','',')

See the problem fields:

'BidIDFile',
'Addend1',
'SignInSheet',
'TabSheet'

The should not have single quotes but I could not figure out another way of getting array:

Code:
//start creating Addend from position 1 instead of position 0. e.g: Addend1,... Addend6
            $sqlArr['values'][$i += 1]   =   "'".ms_escape_string($_FILES['item']['name'][$i])."'";
            $sqlArr['columns'][]  =   "BidIDFile";
            $sqlArr['columns'][$i]  =   "Addend".$i;
            $sqlArr['columns'][]  =   "SignInSheet";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top