gpt4 book ai didi

javascript - $_POST 在 PHP 中不起作用。也尝试过 $_REQUEST

转载 作者:行者123 更新时间:2023-11-27 22:58:12 24 4
gpt4 key购买 nike

这是我的 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 和名称。

最佳答案

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

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

在你的 JavaScript 中

 <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)
{
$('#myForm').submit();
}
else
{
alert("Please enter correct username and password!");
}
}
});

});

关于javascript - $_POST 在 PHP 中不起作用。也尝试过 $_REQUEST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37388302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com