Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,385
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    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.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,385
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    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.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    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();


  • Users who have thanked rafiki for this post:

    mlseim (08-31-2007)

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!!!

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,385
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •