Calling a PHP function from an HTML form in the same file

后端 未结 10 1437
无人共我
无人共我 2020-12-05 05:48

I\'m trying to execute a PHP function in the same page after the user enters a text and presses a submit button.

The first I think of is using forms. When the user s

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 06:17

    Here is a full php script to do what you're describing, though pointless. You need to read up on server-side vs. client-side. PHP can't run on the client-side, you have to use javascript to interact with the server, or put up with a page refresh. If you can't understand that, there is no way you'll be able to use my code (or anyone else's) to your benefit.

    The following code performs AJAX call without jQuery, and calls the same script to stream XML to the AJAX. It then inserts your username and a
    in a div below the user box.

    Please go back to learning the basics before trying to pursue something as advanced as AJAX. You'll only be confusing yourself in the end and potentially wasting other people's money.

    ".$_GET["user"].""; //output an xml document.
        }
        if(isset($_GET["user"])){
            test();
        } else {
    ?>
        
            Test
            
        
        
            

提交回复
热议问题