Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-30-2007, 07:20 PM   PM User | #1
sesc
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
sesc is an unknown quantity at this point
Unhappy Unable to upload and post the form

I have a form with two fields. username , password. Also I have a file field where I can browse for a file. I have two buttons labeled 'Upload file' and 'Submit Form'. When I browse the file using file field and click on upload file button, the file needs to be moved to the directory in the server. then when I click on Submit form button after entering the username and password values, then these two values should be in to the database.

I am able to do these two actions independently. But where as when I mix these two I am unable to do this. Do I need to use two forms or one form is fine?. I am posting the code for one form that I am currently having.

Here is the form code:

<form name="submitFrm" method="post" enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>">
username : <input name="usernm" type="text" size="30" maxlength="50" >
password : <input name="passwd" type="text" size="30" maxlength="50" >

Upload Img <input name="image" type="file" >

<input name="Upload" type="button" value="Upload " onClick="javascript:return upload_image();">

<input name="submit" type="button" value="Submit " onClick="javascript:return validate();">

</form>

should I have other php page for the 'action=' value. Please help me in getting this done. Thanks in advance. Please let me know if this is confusing?
sesc is offline   Reply With Quote
Old 08-30-2007, 08:01 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Is this a thing where the person needs to be logged-in before they can upload a file?

I'm a bit confused as to what the relationship is between the two things.
mlseim is offline   Reply With Quote
Old 08-30-2007, 09:53 PM   PM User | #3
sesc
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
sesc is an unknown quantity at this point
user is presented with two text fields to input, then one file field to upload the file, then two buttons one to upload the file and second to insert the text values into the database.
sesc is offline   Reply With Quote
Old 08-30-2007, 10:44 PM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
You need to use 2 forms. The first upload button is acting as a submit button. You could use ajax though I don't know if you can actually upload files to a server using it.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 08-31-2007, 01:01 AM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
How about one form.

If they don't select a file, don't do the upload part.
If they don't put in an ID or Password, don't to that part.

The one form can be sent to one script that can do both,
depending on what was selected.
mlseim is offline   Reply With Quote
Old 08-31-2007, 01:08 AM   PM User | #6
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
Quote:
Originally Posted by mlseim View Post
How about one form.

If they don't select a file, don't do the upload part.
If they don't put in an ID or Password, don't to that part.

The one form can be sent to one script that can do both,
depending on what was selected.
PHP Code:
if (isset($_POST['uname']) && isset($_POST['pass'])) {
// do one thing
foo();
}elseif(isset(
$_POST['other'])){
// do other thing
bar();
}else{
//show form
show_form();

__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Users who have thanked rafiki for this post:
mlseim (08-31-2007)
Old 08-31-2007, 02:20 PM   PM User | #7
sesc
New Coder

 
Join Date: Aug 2007
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
sesc is an unknown quantity at this point
I don't mind with one form. My main requirement is user would be entering all the details (username and password) and also should upload an image. I used both the buttons as 'Type = Button' not submit.
Please help me in getting this done. Thanks in advance!!!
sesc is offline   Reply With Quote
Old 08-31-2007, 07:26 PM   PM User | #8
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
oh, well then one form and maybe some Javascripting to make sure they
properly entered a username and password and selected an image.

This would all happen on one PHP script (not two). You can use the
script to upload the image and then move to the proper directory using
the username and password.

I like using this Javascript for form validation:
http://www.massimocorner.com/validator/index.htm

Sorry I don't have time to write a complete script (holiday weekend you know),
but you only need one form and one script (you can even make them the
same file, calling itself if you want). All in one script.

What happens with the login? Do you compare the username and password
to something in a MySQL database? How you do determing which
directory to go, and how are the directories secured?

With more information on what your site is supposed to do, and the purpose
of the script ... we might be able to provide some better examples.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:29 PM.


Advertisement
Log in to turn off these ads.