HTML按钮提交不激活php代码

问题描述:

我遇到了我的html表单没有正确提交的问题。我是新来的形式,并一直试图让登录脚本去,但它一直在失败。我大多使用铬。这是超级愚蠢的代码,希望能够证明我的问题。我猜测这段代码在扩展代码中出了什么问题。这是我用我的登录编码的网站:login account setup site mainly for referenceHTML按钮提交不激活php代码

<?php 
 

 
//this is here for testing 
 
session_start(); 
 

 
//this shows 
 
echo "something"; 
 

 
//none of these show 
 
if(isset($_POST['submit'])){ 
 

 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
} 
 
if(isset($_POST['submit2'])){ 
 

 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
}if(isset($_POST['submit3'])){ 
 

 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
    echo "something"; 
 
} 
 

 
?> 
 

 
<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="UTF-8"> 
 
</head> 
 
<body> 
 
<footer> 
 
    <!-- I have tried it with and without an action --> 
 
    <form action="button_test.php" method="post" id="this" style="width: 100%; height: 100%; background-color: darkblue;"> 
 
     <button type="submit" name="submit" id="submit" class="button" value="Submit">this is something</button> 
 
     <button type="button" name="submit2" id="submit2" class="button" value="this">this is something2</button> 
 
     <input type="button" name="submit3" id="submit3" class="button" value="true"/> 
 
    </form> 
 
</footer> 
 
</body> 
 
</html>

的第一个按钮可预见的重新加载页面,而其他的什么也不做。这是我需要工作的扩展主代码。再次,我猜测上面的代码可能解释了下面的代码有什么问题。下面的代码主要是为了给出上下文和更准确的答案。

<?php 
 

 
//require once the DatabaseController.php file, 
 
require_once 'Controllers/DatabaseController.php'; 
 
echo "this happend1"; 
 
// Creates a data connect object that creates a connection to 
 
// a database 
 
$connection = new DataConnect; 
 
//Run the user_load function to set the user 
 
$connection->user_load(); 
 
echo "this happend2"; 
 
/* 
 
* Runs the in_loggedin function from a 
 
* user object and checks if it is blank 
 
*/ 
 
if($user->is_loggedin()!="") 
 
{ 
 
    echo "this happend3"; 
 
    //return user to logged in home page if 
 
    //they are logged in 
 
    $user->redirect('index.php'); 
 
} 
 
echo "this happend4"; 
 
/* 
 
* THIS DOES NOT WORK FOR SOME REASON 
 
*/ 
 
if(isset($_POST['btn-login'])) 
 
{ 
 
    echo "this happend5"; 
 
    //Load the variables with the new form data that has been executed 
 
    $uname = $_POST['txt_uname_email']; 
 
    $umail = $_POST['txt_uname_email']; 
 
    $upass = $_POST['txt_password']; 
 

 
    //If the user->login call is successful, go to home fully logged in 
 
    if($user->login($uname,$umail,$upass)) 
 
    { 
 
     //Go to home, fully logged in 
 
     $user->redirect('index.php'); 
 
    } 
 
    else 
 
    { 
 
     //Error 
 
     $error = "Wrong Details !"; 
 
    } 
 
} 
 
?> 
 

 

 
<!DOCTYPE html> 
 
<html lang="en-US"> 
 
    <head> 
 
     <meta charset="UTF-8"> 
 
     <title> Josiah</title> 
 

 
     <link href="Assets/Stylesheets/styles-home.css" type="text/css" rel="stylesheet" /> 
 
    </head> 
 
    <body> 
 
     <?php 
 
     include_once 'header.php'; 
 
     ?> 
 

 
<!-- recent blog post: contains the most recent blog post--> 
 
<div id="main-content" class="content"> 
 
    <div id="main-content-inner" class="inner-content"> 
 
     <!-- this is the container for the form --> 
 
     <div class="form-container"> 
 
      <!-- create a form that uses the "post" method which allows php to do $_POST on 
 
      corresponding variable names --> 
 
      <form method="post"> 
 

 
       <h2>Sign in.</h2><hr /> 
 
       <!-- checks if there was an error. If the error variable is set --> 
 
       <?php 
 
       if(isset($error)) 
 
       { 
 
        ?> 
 
        <!-- displays the error --> 
 
        <div class="alert alert-danger"> 
 
         <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?> ! 
 
        </div> 
 
        <?php 
 
       } 
 
       ?> 
 
       <!-- this is a form-group --> 
 
       <div class="form-group"> 
 
        <!-- this is a text input. --> 
 
        <input type="text" class="form-control" name="txt_uname_email" placeholder="Username or E mail ID" required /> 
 
       </div> 
 
       <!-- this is a form-group --> 
 
       <div class="form-group"> 
 
        <!-- this is a text input. --> 
 
        <input type="password" class="form-control" name="txt_password" placeholder="Your Password" required /> 
 
       </div> 
 
       <!-- splits parts of the form --> 
 
       <div class="clearfix"></div><hr /> 
 
       <!-- this is a form group holdng the submit button --> 
 
       <div class="form-group"> 
 
        <!-- the button interestingly has multiple classes --> 
 
        <button type="submit" name="btn-login" class="btn btn-block btn-primary"> 
 
         <!-- splits parts of the form. Dont know specifically what this does. --> 
 
         <i class="glyphicon glyphicon-log-in"></i>&nbsp;SIGN IN 
 
        </button> 
 
       </div> 
 
       <br /> 
 
       <label>Don't have account yet ! <a href="sign-up.php">Sign Up</a></label> 
 
      </form> 
 
     </div> 
 
    </div> 
 
</div> 
 

 
<!-- footer: contains social media, site map, and an up arrow--> 
 
<?php 
 
include 'footer.php' 
 
?> 
 
</body> 
 
</html>

+0

让我们来测试:在脚本的顶部,你做'的var_dump($ _ POST)'和'回声的file_get_contents( 'PHP://输入')',在每行显示的内容? – BeetleJuice

+0

我得到:array(0){} submit =提交 –

+0

它似乎是通过按钮值,但我希望它通过按钮名称,我虽然它。我引用的网站和扩展的代码没有使用按钮中的值字段,我觉得我想保持这种方式,除非绝对需要。看来,如果声明 –

因此,经过一些搜索,我忘记透露我正在使用PHPstorm。之所以没有发生这种情况,是因为PHPstorm没有安装在我一直使用的另一台计算机上,但是由于我在两台计算机上都使用了Intellij,所以无论因为Intellij如何,PHPstorm中的这个错误都会使用PHPstorm插件。看来10.1-10.3这个bug在POST保持空白的地方依然存在。我不确定它是否被修复,所以我转移到了Apache,并且让它做了Web服务。一切正常,或至少效果更好。这两个解决方案要么等待PHPstorm来修复这个bug,要么更好地转向Apache。

link to site post

由于php://input显示形式值(根据测试我有你的意见运行),我们知道,PHP被正确接收数据。

默认情况下,PHP会根据需要在$_GET$_POST中放置请求参数。在你的情况下,这似乎并没有发生。我建议你看一下你的php.ini文件,并添加以下设置:

variables_order = "GPCS" 

可能已经有一个variables_order线,所以只是在这种情况下(documentation)编辑它。

+0

variables_order =“GPCS”已经在我的ini中设置了 –

+0

它没有被评论正确吗? (以';'开头)。如果是这样,请取消注释。您还需要重新启动PHP才能使更改生效。 – BeetleJuice

+0

是的,它已经在那里。 $ _POST一直工作正常。我设置了“$ _POST ['this thing'] = 6;”在var转储之前,将其中一个if语句设置为“if(isset($ _ POST ['this thing']))”并且它可以工作。它似乎是HTML表单不设置发布。如果我移动“$ _POST ['this thing'] = 6;”到页面的末尾,然后没有任何反应。 –