在同一屏幕上运行php函数

在同一屏幕上运行php函数,php,Php,嗨,我对php非常陌生,玩代码学习。我有一个非常基本的登录表单,它有用户名和密码输入以及两个输入按钮 一个用于在数据库中创建条目,另一个用于从数据库中读取 JsFiddle: 我的注册和读取函数位于functions.php文件中 function signUpFunct(){ if(isset($_POST['username']) and isset($_POST['password'])){ $username = $_POST['username']; $passwor

嗨,我对php非常陌生,玩代码学习。我有一个非常基本的登录表单,它有用户名和密码输入以及两个输入按钮 一个用于在数据库中创建条目,另一个用于从数据库中读取

JsFiddle:

我的注册和读取函数位于functions.php文件中

function signUpFunct(){

if(isset($_POST['username']) and isset($_POST['password'])){
    $username = $_POST['username'];
    $password = $_POST['password'];

    $connection = mysqli_connect('localhost','root','','loginPage');

    if($connection){
       $query = "INSERT INTO users(username,password) VALUES ('$username','$password')";
       if($query){
            mysqli_query($connection,$query);   
       }
       else{
           die("Sign Up Failed");
       }
   }
   else{
       die("Failed to Connect Database");
   }
} 
}

这两个功能都可以正常工作,但问题是当我在我所在的浏览器中单击“显示”按钮时


我想做的是在单击显示按钮时在表单页面上显示数据。我该怎么做?

您的代码不安全!为了防止SQL注入,也请阅读以下内容:我知道,这些都是小步骤,在去那里之前我还需要学习更多的东西,谢谢=),但是不管怎样,你的表单是在index.php上还是在别的什么地方?使用php include包含functions.php文件。然后在index.php中调用在functions.php中创建的函数。(将表单上的action参数更改为index.php)。
function readAll(){
    $connection = mysqli_connect('localhost','root','','loginPage');

    if($connection){
       $query = "SELECT * FROM users";
       if($query){
           $result = mysqli_query($connection,$query); 
           while($row = mysqli_fetch_assoc($result)){

               ?>
               <pre>
                   <?php print_r($row);?>
               </pre>
               <?php
           }
       }
       else{
           die("Sign Up Failed");
       }
   }
   else{
       die("Failed to Connect Database");
   }
if(isset($_POST['signUp'])){
    signUpFunct();
}
else if(isset($_POST['display'])){
    readAll();
}