CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 File Upload Store to Database

Print topic Send  topic

Author Message
lgalocgoc2

Posts: 35
Posted: 10/01/2012, 3:52 AM

Hello Everyone,

I am new with codecharge. My problem is I can't store the filename to the database.

Please help.

Thank you.
View profile  Send private message
Lucius

Posts: 220
Posted: 10/01/2012, 5:02 AM

Hi,

Sorry but you need to be more detailed here, what is that you try to achieve? How are you trying to do it? What is the exactly the issue?

Give us some background :)
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/01/2012, 5:20 AM

Hi Lucius,

Thanks for you response.

What I am going to do is create an upload page. I used the File Upload component to browse any file type and upload it to my server as well as to the database.

I was able to upload the file to a folder but I can't upload it to my database table. Eehh, I did upload it to my database table but it accepts only one file. Once a file has been uploaded the "Submit" and the "Delete" button will appear and forced me to delete the file uploaded to the database but not in the folder.

What I want to do is store the files to the folder and store also the filename of each file to my database.

I am not sure the exact settings/properties on codecharge due to the fact that I am new with it.

I really need help. Thanks in advance. :)
View profile  Send private message
Lucius

Posts: 220
Posted: 10/01/2012, 9:00 AM

Ok, so basically you want to update multiple files. Much more clear now :-D

What happens currently for you is:

1st time you load the page with the file upload component it is in Insert state (add new record to the DB).
After you add a file and it is uploaded, the page changes state to Update - this is why you have the delete button.

What you need is to upload 1st file and then go back to Insert state, so you can upload new file.

The easiest way to achieve this (if form should only do Inserts) is to set the form properties in Design mode:
Allow Insert - Yes
Allow Update - No
Allow Delete - No

This will make the form Insert-only form.

However if you would like to edit/delete the values also, I would suggest to try an example:

- In CCS create via Builders "Grid & Record" (single button on Builders ribbon). Grid will be the list of DB entries with ID linking to Record that will allow you to display selected DB record.
- Check how parameters are passed in the URL when you click "Add new", or when you select already created record (from the CCS generated page)
- Use this knowledge to design what you need, it is simple. If you get stuck let us know :)

Also as a footnote make sure that the DB structure is correct (ID's with autoincrement are best if you are learning).
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/03/2012, 2:28 AM

Hi Lucius,

Thanks for the idea.

My problem now is when I tried to insert another file, it says "Database Error: Duplicate entry '2147483647' for key 'PRIMARY'". I am confused with this, I have set my file_id(PK) to autoincrement.

Please help me.

Thank you.
View profile  Send private message
Lucius

Posts: 220
Posted: 10/03/2012, 2:47 AM

Ok, so you are doing an Insert now, but you are passing the ID that is already in the DB.

Check few things:

- when you design Record in the designer, that you correctly selected the ID column (file_id) to mark the Primary Key
- that in the browser URL there isn't a parameter file_id=SOME_NUMBER - this means that even though the form is in Insert mode you pass parameter as you would try to update
- that the form doesn't actually have an input called "file_id" (text, hidden, etc), that you can use to put in some value - when you use autoincrement IDs those are not added in the Records for edit, they are handled internally by CCS <- most likely cause
- check the DB directly, see what ID's are already created and then inspect HTML of webpage (Firefox Firebug plugin is great for this) to check the Form if there is maybe somehow file_id Input element sending this value, that you have missed

Edit:
If you have an ability, temporarily upload this page you have trouble with to some webhost, so we can check it out.
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/03/2012, 3:02 AM

Thank you Lucius.

I did not add a primary key to my database table so it will insert all the uploaded file without restriction of the Primary Key.

Now, how can I get the current user_id so that I can insert it to my file_upload database table?

The attributes for my file_upload table are the following:
file_name varchar(200)
user_id int(11)

The scenario here is, a user will login first before uploading a file. I want to get the current user_id to insert it to the file_upload database table also.
The file_name varchar(200) is the storage for uploaded file name.
The user_id int(11) is the storage of the user id who uploaded a specific file.

How will I do it?

Please help.

Thank you.



View profile  Send private message
Lucius

Posts: 220
Posted: 10/03/2012, 3:05 AM

Check CCS help for - CCGetUserID function :)
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/03/2012, 3:09 AM

Hi Lucius,

Where to edit it so it is also inserted to the database table with the uploaded file name? I mean, they are inserted to the database together, how to do it?

Please help :(
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/03/2012, 3:44 AM

Got it now.

Thanks Lucius for all the help :)
View profile  Send private message
Lucius

Posts: 220
Posted: 10/03/2012, 3:53 AM

There are few ways to do it....

1. You can add a hidden input to form that will be called user_id and then fill it on before show event for Record with user ID from PHP code. However this is a VERY BAD idea in terms of form security - just wanted to show example of what you can do :)

2. You can use Before Build Insert event to modify the Record SQL, so it also adds the user ID to the DB. Use CCGetUserID() function in this PHP server-side event.

3. You can use Custom Insert property for the Record (in the CCS Design view), to create a SQL with parameters. Simpliest would be Custom Insert Type "Table" where you can specify that the user_id field should be filled with Session variable you use to store UserID (you can check it in Project Settings -> Security -> Advanced -> User Id variable --- if you have this configured correctly you will see what this Session variable is called) or even use Application to get the CCGetUserID() function result directly

There are more ways...

What I can suggest is for you to open CCS Help (F1 key) and browse:
Quick Start Tutorials
Example and Techniques

Especially the latter contains what you are looking for:
Example and Techniques -> Programming -> Customizing the Data Source
Example and Techniques -> Programming -> Working With Databases

All your questions are answered in the help file, take some time to read through it, it will make you work much faster later on.
View profile  Send private message
lgalocgoc2

Posts: 35
Posted: 10/03/2012, 4:11 AM

Thanks once again Lucius. Thanks for your time. :)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.