473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Upload Excel files and update mssql db

Hi All,

I wish you a Happy new year!!!..

My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2 input files and update the database. html code for the same

Expand|Select|Wrap|Line Numbers
  1. <table  cellspacing="3" cellpadding="3" style="color:#0000b9; background-color:#d7deec; ">
  2.  <tbody>
  3.     <tr>
  4.           <td>
  5.              <b> <label for="babmpath">BA-BM status file:</label> </b>
  6.           </td>
  7.            <td><input type="file" name="babmpath" id="babmpath"  />
  8.          </td>
  9.     </tr>
  10.     <tr>
  11.           <td>
  12.              <b> <label for="eskal">Escalation file:</label> </b></td>
  13.            <td><input type="file" name="eskal" id="eskal"  /></td>
  14.      </tr>
  15.      <tr>
  16.            <td >
  17.               <b><input type="submit" name="update"
  18.                           value="Update Database"
  19.                           onclick="return confirm('Are you sure that you want  to upload to the database?\n\ \nPlease close the excel file that you want to upload to the database.');" /> </b>
  20.           </td>
  21.        </tr>
  22.       </tbody>
  23.   </table>
The logic that i used to upload the files was:-- Once the user browse for these files and press update button. I am saving the path of the files in another 2 hidden input fields. I am passing the path to the stored procedure in MSSQL.

The code in stored procedure:-


Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[update_db] 
  2.     -- Add the parameters for the stored procedure here
  3.     @ba_bm_status    VARCHAR(100), 
  4.     @eskal VARCHAR(100),
  5.     @error VARCHAR(MAX) OUTPUT
  6. AS
  7. BEGIN
  8.  
  9.     SET NOCOUNT ON;
  10.  
  11. BEGIN TRANSACTION update_database
  12. SET XACT_ABORT ON
  13.  
  14.  
  15. --Importing data using distributed queries
  16.  
  17. SET @error = ''
  18. IF(@ba_bm_status IS NOT NULL)
  19. BEGIN
  20. EXEC('SELECT * INTO temp FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',
  21. ''Excel 8.0;Database=' + @ba_bm_status + ''',' +
  22.  '''SELECT * FROM [qry_BA_Controlling (Report)$]'')');
Here @ba_bm_status is the path of the excel that i am sending from PHP. qry_BA_Controlling (Report) worksheet name in the excel.

Till now it is working fine. Uploading the data from excel and updating it on the server. (Testing is done on the server itself :-p). Now once the code has been deployed i mean made it online. Whenever the user tries to update the database. It is giving me an error message.

The reason behind it was:- As i am just passing the path instead of uploading the files. The path from where are the files are browsed is on the client side and i am searching for the files in the server side(I mean in MSSQL when i am uploading the files).
For example path of the file:- C:\Documents and Settings\l.varada\Desktop\Files\old\eroom_status.x ls

and on execution in MSSQL stored procedure(refer to the code above). It was not able to find the file in this path on the server.

Then i thought for an alternative solution as:- Upload the excel files on to the server and from the server to update the database.

With the little knoweldge i have and after browsing net i have found only method to uplaod file(with input type = file). I am using xampp server and mssql installed with odbc drivers. I have no idea where these files are getting saved on the server.

I would be glad If you can help me further in solving this further or suggest me an alternative solution :-)

Anyways thanks for your patience in reading this...

Regards,
Lakshmi.
Jan 29 '10 #1
1 5107
dgreenhouse
250 Expert 100+
You have to use a <FORM> element and the correct 'ENCTYPE' attribute set as: ENCTYPE="multipart/form-data".

i.e.
Expand|Select|Wrap|Line Numbers
  1. <!-- Stolen from the TUT referenced below...->
  2. <form enctype="multipart/form-data" action="uploader.php" method="POST">
  3.   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  4.   Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  5.   <input type="submit" value="Upload File" />
  6. </form>
  7.  
  8.  
See: http://www.tizag.com/phpT/fileupload.php for a simple tutorial and come back when you've done that.
Jan 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros)...
8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
1
by: Nono | last post by:
Hello, I am trying to update records in my database from excel data using vba editor within excel. In order to launch a query, I use SQL langage in ADO as follwing:...
1
by: Muskito | last post by:
HELP!!! Hello All, I'm using VB.net 2003 and trying to update data in Excel worksheet. The program selects data from the excel, updates something in the MSSQL DB and then tries to update...
3
by: c676228 | last post by:
Hi everyone, I will develop a program to enroll a group of people on-line. Since we don't have number limitation for the people in the group. I am wondering if there is any company allow people...
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
1
by: =?Utf-8?B?TGFtaXM=?= | last post by:
HI, I am doing an aspx application and need to let my users be able to edit the information in my database by the page. My first Idea was to let them export the information to an excel file at...
1
kwaxy
by: kwaxy | last post by:
Hey Frendz, I can upload files into MS Access database, but unable to upload files to MSSQL database using ASP, can anyone help me plz ????
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.