2016-07-24 79 views
-2

我遇到了我的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

它似乎是通過按鈕值,但我希望它通過按鈕名稱,我雖然它。我引用的網站和擴展的代碼沒有使用按鈕中的值字段,我覺得我想保持這種方式,除非絕對需要。看來,如果聲明 –

回答

0

因此,經過一些搜索,我忘記透露我正在使用PHPstorm。之所以沒有發生這種情況,是因爲PHPstorm沒有安裝在我一直使用的另一臺計算機上,但是由於我在兩臺計算機上都使用了Intellij,所以無論因爲Intellij如何,PHPstorm中的這個錯誤都會使用PHPstorm插件。看來10.1-10.3這個bug在POST保持空白的地方依然存在。我不確定它是否被修復,所以我轉移到了Apache,並且讓它做了Web服務。一切正常,或至少效果更好。這兩個解決方案要麼等待PHPstorm來修復這個bug,要麼更好地轉向Apache。

link to site post

0

由於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;」到頁面的末尾,然後沒有任何反應。 –