我创建了一个添加用户页面,可以将用户添加到数据库中,代码如下我想比较两个文本框,如果它们匹配(密码=一致密码),则应将其插入数据库中,我怎样才能在 php 中实现这一点
<?php
require("../connect.php");
error_reporting(0);
/*
if(!(adminsessioncheck()))
header('location:index.php'); */
if(isset($_POST['add']))
{
$username=$_POST['username'];
$password=$_POST['password'];
mysql_query("INSERT INTO user VALUES('','$username','$password')") or die(mysql_error());
}
?>
<div style=" width:250px; margin-left:auto; margin-right:auto;">
<div class="heading1" style="text-align:center">Add a new User</div>
<br>
<form action="" method="post" onsubmit="msgbox()">
<table width="330" height="135" border="0" class="text">
<tr>
<td><label>User Name</label></td>
<td><input type="text" name="username" id="username" required></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input type="password" id="password" name="password" required></td>
</tr>
<tr>
<td><label>Confirm Password</label></td>
<td><input type="password" id="cpassword" name="cpassword" required></td>
</tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td><td align="center"><input type="submit" name="add" value="Add"></td></tr>
</table>
</form>
</div>
</div>
最佳答案
简单。
if($_POST['password'] !== $_POST['cpassword']) {
header("location:index.php")
} else {
mysql_query("INSERT INTO user VALUES('','$username','$password')") or die(mysql_error());
}
关于php - 检查php中两个文本框的值是否相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19310784/