html button to display php script results [duplicate]










-1
















This question already has an answer here:



  • php form - on submit stay on same page

    8 answers



I have this script in a separate file as my index.php.



I want to have a button that if pressed shows the results from my PHP script in the index.php, but when I use



<form action="../inc/script.php" method="post">
<input type="submit" value="Scan">
</form>


it just goes to the script.php page. how can I change it so it stays on index.php and print_r the array from the script on the index.php page?










share|improve this question















marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 14 '18 at 19:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    Read about AJAX

    – SeReGa
    Nov 14 '18 at 18:55











  • the word is method and not methode.

    – Funk Forty Niner
    Nov 14 '18 at 18:55











  • @FunkFortyNiner Not everybody speaks English as a first language.

    – IMSoP
    Nov 14 '18 at 18:58






  • 1





    @IMSoP I know, but syntax is English-based, n'est-ce pas?

    – Funk Forty Niner
    Nov 14 '18 at 18:58











  • @FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

    – IMSoP
    Nov 14 '18 at 19:01















-1
















This question already has an answer here:



  • php form - on submit stay on same page

    8 answers



I have this script in a separate file as my index.php.



I want to have a button that if pressed shows the results from my PHP script in the index.php, but when I use



<form action="../inc/script.php" method="post">
<input type="submit" value="Scan">
</form>


it just goes to the script.php page. how can I change it so it stays on index.php and print_r the array from the script on the index.php page?










share|improve this question















marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 14 '18 at 19:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    Read about AJAX

    – SeReGa
    Nov 14 '18 at 18:55











  • the word is method and not methode.

    – Funk Forty Niner
    Nov 14 '18 at 18:55











  • @FunkFortyNiner Not everybody speaks English as a first language.

    – IMSoP
    Nov 14 '18 at 18:58






  • 1





    @IMSoP I know, but syntax is English-based, n'est-ce pas?

    – Funk Forty Niner
    Nov 14 '18 at 18:58











  • @FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

    – IMSoP
    Nov 14 '18 at 19:01













-1












-1








-1









This question already has an answer here:



  • php form - on submit stay on same page

    8 answers



I have this script in a separate file as my index.php.



I want to have a button that if pressed shows the results from my PHP script in the index.php, but when I use



<form action="../inc/script.php" method="post">
<input type="submit" value="Scan">
</form>


it just goes to the script.php page. how can I change it so it stays on index.php and print_r the array from the script on the index.php page?










share|improve this question

















This question already has an answer here:



  • php form - on submit stay on same page

    8 answers



I have this script in a separate file as my index.php.



I want to have a button that if pressed shows the results from my PHP script in the index.php, but when I use



<form action="../inc/script.php" method="post">
<input type="submit" value="Scan">
</form>


it just goes to the script.php page. how can I change it so it stays on index.php and print_r the array from the script on the index.php page?





This question already has an answer here:



  • php form - on submit stay on same page

    8 answers







php html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 19:11









harmstyler

1,1481020




1,1481020










asked Nov 14 '18 at 18:49









collin 038collin 038

33




33




marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 14 '18 at 19:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Funk Forty Niner html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 14 '18 at 19:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    Read about AJAX

    – SeReGa
    Nov 14 '18 at 18:55











  • the word is method and not methode.

    – Funk Forty Niner
    Nov 14 '18 at 18:55











  • @FunkFortyNiner Not everybody speaks English as a first language.

    – IMSoP
    Nov 14 '18 at 18:58






  • 1





    @IMSoP I know, but syntax is English-based, n'est-ce pas?

    – Funk Forty Niner
    Nov 14 '18 at 18:58











  • @FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

    – IMSoP
    Nov 14 '18 at 19:01












  • 1





    Read about AJAX

    – SeReGa
    Nov 14 '18 at 18:55











  • the word is method and not methode.

    – Funk Forty Niner
    Nov 14 '18 at 18:55











  • @FunkFortyNiner Not everybody speaks English as a first language.

    – IMSoP
    Nov 14 '18 at 18:58






  • 1





    @IMSoP I know, but syntax is English-based, n'est-ce pas?

    – Funk Forty Niner
    Nov 14 '18 at 18:58











  • @FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

    – IMSoP
    Nov 14 '18 at 19:01







1




1





Read about AJAX

– SeReGa
Nov 14 '18 at 18:55





Read about AJAX

– SeReGa
Nov 14 '18 at 18:55













the word is method and not methode.

– Funk Forty Niner
Nov 14 '18 at 18:55





the word is method and not methode.

– Funk Forty Niner
Nov 14 '18 at 18:55













@FunkFortyNiner Not everybody speaks English as a first language.

– IMSoP
Nov 14 '18 at 18:58





@FunkFortyNiner Not everybody speaks English as a first language.

– IMSoP
Nov 14 '18 at 18:58




1




1





@IMSoP I know, but syntax is English-based, n'est-ce pas?

– Funk Forty Niner
Nov 14 '18 at 18:58





@IMSoP I know, but syntax is English-based, n'est-ce pas?

– Funk Forty Niner
Nov 14 '18 at 18:58













@FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

– IMSoP
Nov 14 '18 at 19:01





@FunkFortyNiner Ah, I see your point; your comment still seems blunt though, since it's not actually the answer to the question (which is the classic confusion over server vs client code). It could have been something like "By the way, you have a mistake in your HTML, it should be method= not methode="

– IMSoP
Nov 14 '18 at 19:01












2 Answers
2






active

oldest

votes


















2














The form action tells the browser to post the form results to that page. If you want to stay on the current page you'll need to remove the action. Then, you'll have to check the post and include the results within the current page.



<form method="post">
<input type="submit" name="Scan" value="Scan">
</form>

<?php
if (isset($_POST['Scan']))
include '../inc/script.php';

?>





share|improve this answer























  • thanks this worked perfectly 😃

    – collin 038
    Nov 14 '18 at 19:14


















0














One way to solve this problem is through using JavaScript, and specifically jQuery in my example.



What you would do is set up a POST request to the PHP document, that would return the print_r result. You also won't need a form in this instance, more than a button.



HTML:



<button type="button" id="scan"></button>



AND



<div id="returned-data"></div>



so you have a place to put the data when you get it back.



JS/jQuery:



$(document).ready(function()
$('#scan').click(function()
$.post('../inc/script.php').done(function(data)
$('#returned-data').html(data);
);
);
);


PHP (../inc/script.php):



<?php
//do something with your data, and finish with:
print_r($data);
?>





share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The form action tells the browser to post the form results to that page. If you want to stay on the current page you'll need to remove the action. Then, you'll have to check the post and include the results within the current page.



    <form method="post">
    <input type="submit" name="Scan" value="Scan">
    </form>

    <?php
    if (isset($_POST['Scan']))
    include '../inc/script.php';

    ?>





    share|improve this answer























    • thanks this worked perfectly 😃

      – collin 038
      Nov 14 '18 at 19:14















    2














    The form action tells the browser to post the form results to that page. If you want to stay on the current page you'll need to remove the action. Then, you'll have to check the post and include the results within the current page.



    <form method="post">
    <input type="submit" name="Scan" value="Scan">
    </form>

    <?php
    if (isset($_POST['Scan']))
    include '../inc/script.php';

    ?>





    share|improve this answer























    • thanks this worked perfectly 😃

      – collin 038
      Nov 14 '18 at 19:14













    2












    2








    2







    The form action tells the browser to post the form results to that page. If you want to stay on the current page you'll need to remove the action. Then, you'll have to check the post and include the results within the current page.



    <form method="post">
    <input type="submit" name="Scan" value="Scan">
    </form>

    <?php
    if (isset($_POST['Scan']))
    include '../inc/script.php';

    ?>





    share|improve this answer













    The form action tells the browser to post the form results to that page. If you want to stay on the current page you'll need to remove the action. Then, you'll have to check the post and include the results within the current page.



    <form method="post">
    <input type="submit" name="Scan" value="Scan">
    </form>

    <?php
    if (isset($_POST['Scan']))
    include '../inc/script.php';

    ?>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 19:09









    harmstylerharmstyler

    1,1481020




    1,1481020












    • thanks this worked perfectly 😃

      – collin 038
      Nov 14 '18 at 19:14

















    • thanks this worked perfectly 😃

      – collin 038
      Nov 14 '18 at 19:14
















    thanks this worked perfectly 😃

    – collin 038
    Nov 14 '18 at 19:14





    thanks this worked perfectly 😃

    – collin 038
    Nov 14 '18 at 19:14













    0














    One way to solve this problem is through using JavaScript, and specifically jQuery in my example.



    What you would do is set up a POST request to the PHP document, that would return the print_r result. You also won't need a form in this instance, more than a button.



    HTML:



    <button type="button" id="scan"></button>



    AND



    <div id="returned-data"></div>



    so you have a place to put the data when you get it back.



    JS/jQuery:



    $(document).ready(function()
    $('#scan').click(function()
    $.post('../inc/script.php').done(function(data)
    $('#returned-data').html(data);
    );
    );
    );


    PHP (../inc/script.php):



    <?php
    //do something with your data, and finish with:
    print_r($data);
    ?>





    share|improve this answer



























      0














      One way to solve this problem is through using JavaScript, and specifically jQuery in my example.



      What you would do is set up a POST request to the PHP document, that would return the print_r result. You also won't need a form in this instance, more than a button.



      HTML:



      <button type="button" id="scan"></button>



      AND



      <div id="returned-data"></div>



      so you have a place to put the data when you get it back.



      JS/jQuery:



      $(document).ready(function()
      $('#scan').click(function()
      $.post('../inc/script.php').done(function(data)
      $('#returned-data').html(data);
      );
      );
      );


      PHP (../inc/script.php):



      <?php
      //do something with your data, and finish with:
      print_r($data);
      ?>





      share|improve this answer

























        0












        0








        0







        One way to solve this problem is through using JavaScript, and specifically jQuery in my example.



        What you would do is set up a POST request to the PHP document, that would return the print_r result. You also won't need a form in this instance, more than a button.



        HTML:



        <button type="button" id="scan"></button>



        AND



        <div id="returned-data"></div>



        so you have a place to put the data when you get it back.



        JS/jQuery:



        $(document).ready(function()
        $('#scan').click(function()
        $.post('../inc/script.php').done(function(data)
        $('#returned-data').html(data);
        );
        );
        );


        PHP (../inc/script.php):



        <?php
        //do something with your data, and finish with:
        print_r($data);
        ?>





        share|improve this answer













        One way to solve this problem is through using JavaScript, and specifically jQuery in my example.



        What you would do is set up a POST request to the PHP document, that would return the print_r result. You also won't need a form in this instance, more than a button.



        HTML:



        <button type="button" id="scan"></button>



        AND



        <div id="returned-data"></div>



        so you have a place to put the data when you get it back.



        JS/jQuery:



        $(document).ready(function()
        $('#scan').click(function()
        $.post('../inc/script.php').done(function(data)
        $('#returned-data').html(data);
        );
        );
        );


        PHP (../inc/script.php):



        <?php
        //do something with your data, and finish with:
        print_r($data);
        ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 18:58









        RyanRyan

        3169




        3169













            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線