如何使用php区分同一html表单中的不同输入
我正在用php构建一个聊天机器人。我希望聊天机器人的功能是用于重置密码,因此它要求员工的如何使用php区分同一html表单中的不同输入,php,html,Php,Html,我正在用php构建一个聊天机器人。我希望聊天机器人的功能是用于重置密码,因此它要求员工的PIS_code,它将其用作密码列中更改密码的主键,您可以看到我的数据库表 请看,它有PIS\u code和password列,因此我要求用户输入PIS\u code,然后它要求用户输入新密码,然后在相应列中更改密码 因此,我能够使用PIS_代码并将其用作重置密码的主键,但重置的密码是PIS_代码本身 看这里,我想重置41000000PIS_code的密码,但它自己将密码重置为41000000。因此,我的
PIS_code
,它将其用作密码列中更改密码的主键,您可以看到我的数据库表
请看,它有PIS\u code
和password列,因此我要求用户输入PIS\u code
,然后它要求用户输入新密码,然后在相应列中更改密码
因此,我能够使用PIS_代码
并将其用作重置密码的主键,但重置的密码是PIS_代码
本身
看这里,我想重置41000000PIS_code
的密码,但它自己将密码重置为41000000。因此,我的聊天机器人似乎假设输入值是pis代码,并且它仅使用该值更新密码列,因此我的聊天机器人无法区分不同的输入。另外,我只想使用一个表单和一个输入字段。
你可以在这里看到我的聊天机器人
HTML代码:
<div class="form-group">
<form action="process.php" id="form" name="f2" method="POST" >
<input type="textarea" id="tt" name="input" placeholder="Type Your Message" style="position:absolute; bottom:0; height:30px; width:100%; height:50px;" required />
</div>
// this is the code which takes the input for the PIS_CODE
$msgg=$_POST['input'];
// this is the code which takes the input for the password
$pass=$_POST['input'];
// the problem is it saves the same input(that is PIS_CODE) in both the variables($msgg and $pass)
<?php
require_once("config.php");
$msgg=$_POST['input'];
$msg=strtolower($msgg);
$ID = $msg;
$length=strlen($msg);
$flag=0;
$pass=$_POST['input'];
$update = "UPDATE lala SET password='$pass' WHERE PIS_CODE=".$msg;
$res_4=mysqli_query($con,$update);
$sql1 = "SELECT * FROM lala WHERE PIS_CODE='$msg'";
$res_u = mysqli_query($con, $sql1);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.in
{
background-color:rgb(64,128,255);
color:white;
padding:10px;
right:0;
width:130px;
text-align: center;
height:auto;
border-radius: 5px;
margin-left: 120px;
margin-bottom: 5px;
}
.out
{
background-color:rgb(241,240,240);
color:black;
padding:10px;
left:5;
width:130px;
text-align: center;
height:auto;
border-radius: 15px;
}
</style>
<body>
<div class="in">
<?php echo "$msgg"; ?>
</div><br>
<div class="out">
<?php
if (($_POST['input']) =='password reset')
{
echo "Do you want to reset your password? ";
}
else if (($_POST['input']) =='yes')
{
echo "Sure, Please provide PIS code ";
}
if (mysqli_num_rows($res_u) == 1)
{
echo 'Pis verified';
echo "Enter new password";
}
if($update){//if the update worked
echo "Update successful!";
}
?>
</div><br>
</body>
</html>
//这是接收PIS_代码输入的代码
$msgg=$_POST['input'];
//这是接受密码输入的代码
$pass=$_POST['input'];
//问题是它在变量($msgg和$pass)中保存了相同的输入(即PIS_代码)
完整代码:
<div class="form-group">
<form action="process.php" id="form" name="f2" method="POST" >
<input type="textarea" id="tt" name="input" placeholder="Type Your Message" style="position:absolute; bottom:0; height:30px; width:100%; height:50px;" required />
</div>
// this is the code which takes the input for the PIS_CODE
$msgg=$_POST['input'];
// this is the code which takes the input for the password
$pass=$_POST['input'];
// the problem is it saves the same input(that is PIS_CODE) in both the variables($msgg and $pass)
<?php
require_once("config.php");
$msgg=$_POST['input'];
$msg=strtolower($msgg);
$ID = $msg;
$length=strlen($msg);
$flag=0;
$pass=$_POST['input'];
$update = "UPDATE lala SET password='$pass' WHERE PIS_CODE=".$msg;
$res_4=mysqli_query($con,$update);
$sql1 = "SELECT * FROM lala WHERE PIS_CODE='$msg'";
$res_u = mysqli_query($con, $sql1);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.in
{
background-color:rgb(64,128,255);
color:white;
padding:10px;
right:0;
width:130px;
text-align: center;
height:auto;
border-radius: 5px;
margin-left: 120px;
margin-bottom: 5px;
}
.out
{
background-color:rgb(241,240,240);
color:black;
padding:10px;
left:5;
width:130px;
text-align: center;
height:auto;
border-radius: 15px;
}
</style>
<body>
<div class="in">
<?php echo "$msgg"; ?>
</div><br>
<div class="out">
<?php
if (($_POST['input']) =='password reset')
{
echo "Do you want to reset your password? ";
}
else if (($_POST['input']) =='yes')
{
echo "Sure, Please provide PIS code ";
}
if (mysqli_num_rows($res_u) == 1)
{
echo 'Pis verified';
echo "Enter new password";
}
if($update){//if the update worked
echo "Update successful!";
}
?>
</div><br>
</body>
</html>
您可以使用PHP
会话。这将满足您的要求:
require_once("config.php");
$msgg=$_POST['input'];
$msg=strtolower($msgg);
$ID = $msg;
$length=strlen($msg);
$flag=0;
session_start();
if(isset($_SESSION['PIS_CODE'])){
$pass=$_POST['input'];
$update = "UPDATE lala SET password='$pass' WHERE PIS_CODE=".$_SESSION['PIS_CODE'];
$res_4=mysqli_query($con,$update);
unset($_SESSION['PIS_CODE']);
}
else{
$sql1 = "SELECT * FROM lala WHERE PIS_CODE='$msg'";
$res_u = mysqli_query($con, $sql1);
if (mysqli_num_rows($res_u) == 1) {
$_SESSION['PIS_CODE'] = $msg;
}
}
如果我是你(即在聊天机器人上工作),我会使用$\u SESSION
对象来完成更多的任务。您可以保留简单的1输入表单,并使用PHP
session来保存有关下一个预期答案的信息,或者针对一系列问题(如您的示例),以了解当前问题是什么,以及许多其他可能的用法。但如果我添加另一个输入字段,它将不起作用永远不会以纯文本形式存储密码!您应该始终使用哈希值对密码进行哈希,并且只存储哈希值。然后,您可以使用验证密码是否符合哈希。警告!您完全可以接受SQL注入攻击!您应该使用参数化,而不是直接在您的查询中使用完全未跳过的用户数据。这是一个正在进行的代码。在我能够解决此问题之后,当然我将对其进行加密。您可以对其进行加密,但它仍然容易受到SQL注入的攻击。认真对待Magnus的警告,否则会有人很容易破坏你的数据库。我对这一点不熟悉,所以你是说我可以使用会话来保存有关下一个预期答案的信息,我如何才能做到这一点?