$ _POST无法在PHP中运行。已经尝试过$ _REQUEST了

时间:2016-05-23 10:15:18

标签: javascript php html

这是我的HTML

   <form class="login-form" method="POST"> 
      <input type="password" placeholder="password" id="password" name="password"/>
      <input type="button" id="login" name="login" value="login" onclick="redirect()"></input>
        </form>

我的JS

         <script type="text/javascript">
        $(document).ready(function redirect(){
        $("#login").click(function(){
        var pwd="<?php echo $pwd?>";
        alert("<?php echo "this is pass".$pword?>");
        if(userID===user && pwd===pass)
        {
        window.location.href = 'http://localhost/Annapoorna/Welcome_Page.php';
        }
        else
      {
         alert("Please enter correct username and password!");
      }
        }
    });
});
</script>

和PHP

 <?php
     $username="";
     $pwd="";
     $pword="";
     function confirm(){


        if(isset($_REQUEST['password']))
        {
            $pword = $_REQUEST['password'];
        }

        $sth->execute(array(':pass'=>$pword));
        foreach ($sth->fetchAll() as $row) {
        $username=$row['username'];
        $pwd=$row['password'];
        echo $pword;
        }
   ?>     

$ _ POST没有返回任何值。尝试了$ _REQUEST,但没有奏效。还为密码字段分配了ID和名称。

1 个答案:

答案 0 :(得分:1)

您没有提交表单,只是将用户重定向到该页面。试试这个

exportAppnStatusList.map { (dict:[Stirng:String]) -> Contract in 
    return Contract(contractID:dict["contractID"],
                    ebState:dict["ExporterBankState"],
                    ibState:dict["ImporterBankState"],      
                    importerState:dict["ImporterState"], 
                    exportersBankRefNo:dict["ExporterBankRefNo"], 
                    importersBankRefNo:dict["ImporterBankRefNo"] 
}

在你的javascript中

<form id='myForm' class="login-form" method="POST" action='/Annapoorna/Welcome_Page.php'> 
  <input type="password" placeholder="password" id="password" name="password"/>
  <input type="button" id="login" name="login" value="login" onclick="redirect()"></input>
    </form>

});