...

View Full Version : Unable to upload and post the form



sesc
08-30-2007, 08:20 PM
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?

mlseim
08-30-2007, 09:01 PM
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.

sesc
08-30-2007, 10:53 PM
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.

_Aerospace_Eng_
08-30-2007, 11:44 PM
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.

mlseim
08-31-2007, 02:01 AM
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.

rafiki
08-31-2007, 02:08 AM
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.


if (isset($_POST['uname']) && isset($_POST['pass'])) {
// do one thing
foo();
}elseif(isset($_POST['other'])){
// do other thing
bar();
}else{
//show form
show_form();
}

sesc
08-31-2007, 03:20 PM
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!!!

mlseim
08-31-2007, 08:26 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum