我想通过mysql数据库检查udise代码是否已经存在…我的代码如下。。。如何验证此字段?请帮忙
<?php
include('logprocess.php') ?>
<html>
<head>
<title>Login Form </title>
<link rel="stylesheet" href="stylelogin.css">
</head>
<body>
</body>
<form action="regnew.php" method="GET" id="register_form">
<h1>---- </br>
<br>
LOGIN</br></h1>
<div>
<input type="number" placeholder="Enter Your UDISE Code "maxlength="11" id="udise" name="udise">
</div>
<br>
<div>
<button type="submit" name="register" id="reg_btn">Enter</button>
</div>
</br>
<span class="footer"></span>
</form>
</body>
</html>
我的php代码如下。。我已将其保存为不同的文件,并使用include选项调用该文件。但什么都没用
<?php
// Grab User submitted information
// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected successfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
$udise = "";
// Select the database to use
$db = mysql_select_db("workspace",$con);
if (isset($_POST['register'])) {
$sql_udise = "SELECT * FROM udise WHERE schcd='$udise'" or die (mysql_error());
$res_udise = mysqli_query($db, $sql_udise) or die(mysql_error());
$row = mysqli_fetch_assoc($res_udise);
$fields = array( 'udise');
$error = false; //No errors yet
foreach($fields AS $fieldname) { //Loop trough each field
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
echo '<script language="javascript">
alert("Pls Enter All Fields");
</script>'; //Display error with field
$error = true; //Yup there are errors
}
}
if(!$error) {
if($row["udise"]==$udise ){
echo '<script language="javascript">
top.location.href = "updatewp.php"; //the page to redirect
</script>';
}else {
echo '<script language="javascript">
alert("Sorry... UDISE Mismatch pls try again ");
href = "login.php"; //the page to redirect
</script>';}
{
echo '<script language="javascript">
href = "login.php"; //the page to redirect
</script>';
}
mysql_close($con);
}}
?>
如何将此添加到登录表单验证
2条答案
按热度按时间jhkqcmku1#
试试这个代码。
e37o9pze2#
试试这个代码。