How to combine two submit button for file upload and form submit for MySQL












-1














I have two PHP Scripts, one is a simple form for data entry and one is for file upload. I have combined both in one PHP file so data can be submitted to MySQL database and file can be uploaded with the single submit of the button



Both scripts are working fine separately but how can I combine them so it can do both with the single submit button?



add.html (HTML Form)
add.PHP (Uploading data to My SQL and File to destination folder)



PHP and HTML code link Not able to post the PHP code here hope this help.










share|improve this question


















  • 1




    Please post what you tried so far.
    – Kamal
    Dec 27 at 13:10










  • Hi Kamal i have posted the link of code I'm unable to post the code here
    – Yatendra Ranawat
    Dec 27 at 13:15










  • Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
    – Kamal
    Dec 27 at 13:17










  • this is what I'm unable to do.
    – Yatendra Ranawat
    Dec 27 at 13:21










  • I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
    – Yatendra Ranawat
    Dec 27 at 13:23
















-1














I have two PHP Scripts, one is a simple form for data entry and one is for file upload. I have combined both in one PHP file so data can be submitted to MySQL database and file can be uploaded with the single submit of the button



Both scripts are working fine separately but how can I combine them so it can do both with the single submit button?



add.html (HTML Form)
add.PHP (Uploading data to My SQL and File to destination folder)



PHP and HTML code link Not able to post the PHP code here hope this help.










share|improve this question


















  • 1




    Please post what you tried so far.
    – Kamal
    Dec 27 at 13:10










  • Hi Kamal i have posted the link of code I'm unable to post the code here
    – Yatendra Ranawat
    Dec 27 at 13:15










  • Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
    – Kamal
    Dec 27 at 13:17










  • this is what I'm unable to do.
    – Yatendra Ranawat
    Dec 27 at 13:21










  • I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
    – Yatendra Ranawat
    Dec 27 at 13:23














-1












-1








-1







I have two PHP Scripts, one is a simple form for data entry and one is for file upload. I have combined both in one PHP file so data can be submitted to MySQL database and file can be uploaded with the single submit of the button



Both scripts are working fine separately but how can I combine them so it can do both with the single submit button?



add.html (HTML Form)
add.PHP (Uploading data to My SQL and File to destination folder)



PHP and HTML code link Not able to post the PHP code here hope this help.










share|improve this question













I have two PHP Scripts, one is a simple form for data entry and one is for file upload. I have combined both in one PHP file so data can be submitted to MySQL database and file can be uploaded with the single submit of the button



Both scripts are working fine separately but how can I combine them so it can do both with the single submit button?



add.html (HTML Form)
add.PHP (Uploading data to My SQL and File to destination folder)



PHP and HTML code link Not able to post the PHP code here hope this help.







php html mysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 27 at 13:06









Yatendra Ranawat

146




146








  • 1




    Please post what you tried so far.
    – Kamal
    Dec 27 at 13:10










  • Hi Kamal i have posted the link of code I'm unable to post the code here
    – Yatendra Ranawat
    Dec 27 at 13:15










  • Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
    – Kamal
    Dec 27 at 13:17










  • this is what I'm unable to do.
    – Yatendra Ranawat
    Dec 27 at 13:21










  • I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
    – Yatendra Ranawat
    Dec 27 at 13:23














  • 1




    Please post what you tried so far.
    – Kamal
    Dec 27 at 13:10










  • Hi Kamal i have posted the link of code I'm unable to post the code here
    – Yatendra Ranawat
    Dec 27 at 13:15










  • Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
    – Kamal
    Dec 27 at 13:17










  • this is what I'm unable to do.
    – Yatendra Ranawat
    Dec 27 at 13:21










  • I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
    – Yatendra Ranawat
    Dec 27 at 13:23








1




1




Please post what you tried so far.
– Kamal
Dec 27 at 13:10




Please post what you tried so far.
– Kamal
Dec 27 at 13:10












Hi Kamal i have posted the link of code I'm unable to post the code here
– Yatendra Ranawat
Dec 27 at 13:15




Hi Kamal i have posted the link of code I'm unable to post the code here
– Yatendra Ranawat
Dec 27 at 13:15












Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
– Kamal
Dec 27 at 13:17




Yes, checked your code from link but here by what you tried mean, what exactly you did, have you combined both $_POST['submit'] on a single script, etc.
– Kamal
Dec 27 at 13:17












this is what I'm unable to do.
– Yatendra Ranawat
Dec 27 at 13:21




this is what I'm unable to do.
– Yatendra Ranawat
Dec 27 at 13:21












I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
– Yatendra Ranawat
Dec 27 at 13:23




I am new to PHP and it's not only submitting also redirecting to a new page so it's very confusing
– Yatendra Ranawat
Dec 27 at 13:23












1 Answer
1






active

oldest

votes


















0














Make this type of code



<?php 

if(isset($_POST['Submit'])) {

$email= (!empty($_POST["email"])? $_POST["email"]:"");
$contact_person= (!empty($_POST["contact_person"])? $_POST["contact_person"]:"");
$phone= (!empty($_POST["phone"])? $_POST["phone"]:"");
$mobile= (!empty($_POST["mobile"])? $_POST["mobile"]:"");
$file=upload_file();

if($email&&$contact_person&&$phone&&$mobile&&$file){
insert_admin($email,$contact_person,$phone,$mobile,$file);
header("Location:index.php?r=s");

}else{
$m="Error! cannot add record";
header("Location:add.php?r=e");
}
}


upload function will return file name



function upload_file(){
$result="error";
$path="dist/images/agencylogo/";
$localhost_images_folder=$_SERVER["DOCUMENT_ROOT"]."/".$path;

$image_name=$_FILES['file']['name'];
$file=$_FILES['file']['tmp_name'];
$expbanner=explode('.',$image_name);
$image_extension=$expbanner[1];
$date = time();
$rand=rand(10000,99999);
$img_new_name_h=$date.$rand.".".$image_extension;
$bannerpath=$localhost_images_folder."/".$img_new_name_h;
if($image_extension=="png" || $image_extension=="jpg" || $image_extension=="jpeg"){
if (is_dir("$localhost_images_folder/")) {
if ( is_writable("$localhost_images_folder/")) {
if(move_uploaded_file($_FILES["agency_logo"]["tmp_name"],$bannerpath)){
$result=$img_new_name_h;
}else{
$result="error";
}

}else{
$result="error";
}
}
else{
$result="error";
}
}else{
$result="error";
}
return $result;
}


and insert function will simply insert data into database






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945603%2fhow-to-combine-two-submit-button-for-file-upload-and-form-submit-for-mysql%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Make this type of code



    <?php 

    if(isset($_POST['Submit'])) {

    $email= (!empty($_POST["email"])? $_POST["email"]:"");
    $contact_person= (!empty($_POST["contact_person"])? $_POST["contact_person"]:"");
    $phone= (!empty($_POST["phone"])? $_POST["phone"]:"");
    $mobile= (!empty($_POST["mobile"])? $_POST["mobile"]:"");
    $file=upload_file();

    if($email&&$contact_person&&$phone&&$mobile&&$file){
    insert_admin($email,$contact_person,$phone,$mobile,$file);
    header("Location:index.php?r=s");

    }else{
    $m="Error! cannot add record";
    header("Location:add.php?r=e");
    }
    }


    upload function will return file name



    function upload_file(){
    $result="error";
    $path="dist/images/agencylogo/";
    $localhost_images_folder=$_SERVER["DOCUMENT_ROOT"]."/".$path;

    $image_name=$_FILES['file']['name'];
    $file=$_FILES['file']['tmp_name'];
    $expbanner=explode('.',$image_name);
    $image_extension=$expbanner[1];
    $date = time();
    $rand=rand(10000,99999);
    $img_new_name_h=$date.$rand.".".$image_extension;
    $bannerpath=$localhost_images_folder."/".$img_new_name_h;
    if($image_extension=="png" || $image_extension=="jpg" || $image_extension=="jpeg"){
    if (is_dir("$localhost_images_folder/")) {
    if ( is_writable("$localhost_images_folder/")) {
    if(move_uploaded_file($_FILES["agency_logo"]["tmp_name"],$bannerpath)){
    $result=$img_new_name_h;
    }else{
    $result="error";
    }

    }else{
    $result="error";
    }
    }
    else{
    $result="error";
    }
    }else{
    $result="error";
    }
    return $result;
    }


    and insert function will simply insert data into database






    share|improve this answer


























      0














      Make this type of code



      <?php 

      if(isset($_POST['Submit'])) {

      $email= (!empty($_POST["email"])? $_POST["email"]:"");
      $contact_person= (!empty($_POST["contact_person"])? $_POST["contact_person"]:"");
      $phone= (!empty($_POST["phone"])? $_POST["phone"]:"");
      $mobile= (!empty($_POST["mobile"])? $_POST["mobile"]:"");
      $file=upload_file();

      if($email&&$contact_person&&$phone&&$mobile&&$file){
      insert_admin($email,$contact_person,$phone,$mobile,$file);
      header("Location:index.php?r=s");

      }else{
      $m="Error! cannot add record";
      header("Location:add.php?r=e");
      }
      }


      upload function will return file name



      function upload_file(){
      $result="error";
      $path="dist/images/agencylogo/";
      $localhost_images_folder=$_SERVER["DOCUMENT_ROOT"]."/".$path;

      $image_name=$_FILES['file']['name'];
      $file=$_FILES['file']['tmp_name'];
      $expbanner=explode('.',$image_name);
      $image_extension=$expbanner[1];
      $date = time();
      $rand=rand(10000,99999);
      $img_new_name_h=$date.$rand.".".$image_extension;
      $bannerpath=$localhost_images_folder."/".$img_new_name_h;
      if($image_extension=="png" || $image_extension=="jpg" || $image_extension=="jpeg"){
      if (is_dir("$localhost_images_folder/")) {
      if ( is_writable("$localhost_images_folder/")) {
      if(move_uploaded_file($_FILES["agency_logo"]["tmp_name"],$bannerpath)){
      $result=$img_new_name_h;
      }else{
      $result="error";
      }

      }else{
      $result="error";
      }
      }
      else{
      $result="error";
      }
      }else{
      $result="error";
      }
      return $result;
      }


      and insert function will simply insert data into database






      share|improve this answer
























        0












        0








        0






        Make this type of code



        <?php 

        if(isset($_POST['Submit'])) {

        $email= (!empty($_POST["email"])? $_POST["email"]:"");
        $contact_person= (!empty($_POST["contact_person"])? $_POST["contact_person"]:"");
        $phone= (!empty($_POST["phone"])? $_POST["phone"]:"");
        $mobile= (!empty($_POST["mobile"])? $_POST["mobile"]:"");
        $file=upload_file();

        if($email&&$contact_person&&$phone&&$mobile&&$file){
        insert_admin($email,$contact_person,$phone,$mobile,$file);
        header("Location:index.php?r=s");

        }else{
        $m="Error! cannot add record";
        header("Location:add.php?r=e");
        }
        }


        upload function will return file name



        function upload_file(){
        $result="error";
        $path="dist/images/agencylogo/";
        $localhost_images_folder=$_SERVER["DOCUMENT_ROOT"]."/".$path;

        $image_name=$_FILES['file']['name'];
        $file=$_FILES['file']['tmp_name'];
        $expbanner=explode('.',$image_name);
        $image_extension=$expbanner[1];
        $date = time();
        $rand=rand(10000,99999);
        $img_new_name_h=$date.$rand.".".$image_extension;
        $bannerpath=$localhost_images_folder."/".$img_new_name_h;
        if($image_extension=="png" || $image_extension=="jpg" || $image_extension=="jpeg"){
        if (is_dir("$localhost_images_folder/")) {
        if ( is_writable("$localhost_images_folder/")) {
        if(move_uploaded_file($_FILES["agency_logo"]["tmp_name"],$bannerpath)){
        $result=$img_new_name_h;
        }else{
        $result="error";
        }

        }else{
        $result="error";
        }
        }
        else{
        $result="error";
        }
        }else{
        $result="error";
        }
        return $result;
        }


        and insert function will simply insert data into database






        share|improve this answer












        Make this type of code



        <?php 

        if(isset($_POST['Submit'])) {

        $email= (!empty($_POST["email"])? $_POST["email"]:"");
        $contact_person= (!empty($_POST["contact_person"])? $_POST["contact_person"]:"");
        $phone= (!empty($_POST["phone"])? $_POST["phone"]:"");
        $mobile= (!empty($_POST["mobile"])? $_POST["mobile"]:"");
        $file=upload_file();

        if($email&&$contact_person&&$phone&&$mobile&&$file){
        insert_admin($email,$contact_person,$phone,$mobile,$file);
        header("Location:index.php?r=s");

        }else{
        $m="Error! cannot add record";
        header("Location:add.php?r=e");
        }
        }


        upload function will return file name



        function upload_file(){
        $result="error";
        $path="dist/images/agencylogo/";
        $localhost_images_folder=$_SERVER["DOCUMENT_ROOT"]."/".$path;

        $image_name=$_FILES['file']['name'];
        $file=$_FILES['file']['tmp_name'];
        $expbanner=explode('.',$image_name);
        $image_extension=$expbanner[1];
        $date = time();
        $rand=rand(10000,99999);
        $img_new_name_h=$date.$rand.".".$image_extension;
        $bannerpath=$localhost_images_folder."/".$img_new_name_h;
        if($image_extension=="png" || $image_extension=="jpg" || $image_extension=="jpeg"){
        if (is_dir("$localhost_images_folder/")) {
        if ( is_writable("$localhost_images_folder/")) {
        if(move_uploaded_file($_FILES["agency_logo"]["tmp_name"],$bannerpath)){
        $result=$img_new_name_h;
        }else{
        $result="error";
        }

        }else{
        $result="error";
        }
        }
        else{
        $result="error";
        }
        }else{
        $result="error";
        }
        return $result;
        }


        and insert function will simply insert data into database







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 at 14:09









        Naeem Iqab

        136




        136






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945603%2fhow-to-combine-two-submit-button-for-file-upload-and-form-submit-for-mysql%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'