gpt4 book ai didi

php - 我不知道为什么当我提交时isset函数不起作用

转载 作者:行者123 更新时间:2023-11-29 06:55:16 25 4
gpt4 key购买 nike

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php

$con = mysql_connect('localhost', 'root','');
mysql_select_db ('product');
echo "Connected to database";
session_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Register</title>
<script type="text/javascript" src="assets/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<link rel="stylesheet" href="reg.css" />

<!-- Google Fonts -->
<link href='https://fonts.googleapis.com/css?family=Passion+One' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>

<script src="jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<table align="center">
<td>
<tr>
<div align="center" style="size:30%;" class="container">
<div class="row main" style="width:30%;">
<div class="panel-heading">
<div class="panel-title text-center">
<h1 class="title">Register Here</h1>
<hr />
</div>
</div>
<div class="main-login main-center">
<form class="form-horizontal" method="post" action="<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<div align="left" class="form-group">
<label name="name" class="cols-sm-2 control-label">Your Name</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="name" placeholder="Enter your Name"/>
</div>
</div>
</div>

<div align="left" class="form-group">
<label name="email" class="cols-sm-2 control-label">Your Email</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="email" placeholder="Enter your Email"/>
</div>
</div>
</div>

<div align="left" class="form-group">
<label name="user_name" class="cols-sm-2 control-label">Username</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-users fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="user_name" placeholder="Enter your Username"/>
</div>
</div>
</div>

<div align="left" class="form-group">
<label name="password" class="cols-sm-2 control-label">Password</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
<input type="password" class="form-control" name="password" placeholder="Enter your Password"/>
</div>
</div>
</div>
<div align="left" class="form-group">
<label name="confirm_password" class="cols-sm-2 control-label">Confirm Password</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
<input type="password" class="form-control" name="confirm_password" placeholder="Confirm your Password"/>
</div>
</div>
</div>enter code here

<div align="left" class="form-group ">
<button type="button" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>
</div>
<div class="login-register">
<a href="log.php">Already registered? Login here</a>
</div>
</form>
</div>
</div>
</div>
</tr>
</td>
</table>






<?php

if (isset($_POST['submit']))
{
$name = $_POST['name'];
$username = $_POST['user_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['confirm_password'];
$slquery = "SELECT * FROM customer WHERE email = '$email'";
$selectresult = mysql_query($slquery);
if(empty($_POST['name']))
{
$nameErr='Enter Your Name!';
}
else
{
$user = test_input($_POST['name']);
if(!preg_match('/^[a-zA-Z0-9@_]*$/',$user))
{
$nameErr=' Re-Enter Your Name! Format Inccorrect!( only alpha, numbers,@_ are allowed)';
}
}
if(empty($_POST['password']))
{
$passErr='Enter Your Password!';
}
else
{
$user = test_input($_POST['password']);
if(!preg_match('/^[a-zA-Z0-9@_]*$/',$pass))
{
$passErr='Invalid Format! Re-Enter Password!';
}
}
if(mysql_num_rows($selectresult)>0)
{
$msg = 'email already exists';
}
elseif($password != $cpassword){
$msg = "passwords doesn't match";
}
else{
$query = "INSERT INTO customer (name,email,user_name, password,confirm_password, ) VALUES ('
$name', '$username', '$password', '$cpassword', '$email')";
$result = mysql_query($query);
if($result){
$msg = "User Created Successfully.";
}
}
}

?>


</body>
</html>

我正在尝试创建一个带有验证的注册表单。我使用了一些 Bootstrap 进行前端设计,然后使用 Mysql 数据库和 php。

当我点击提交注册表时,它不会验证字段值。请有人告诉我这有什么问题。而且,它没有显示错误。我不知道为什么这不起作用。

Thank you in Advance.

最佳答案

只需更改此行

<button  type="button" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>

<button  type="submit" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>

您使用了按钮,因此表单未提交。将其更改为提交类型

编辑

注意:请开始使用 PDO 或 mysqli

请检查以下几点:

1) 您已使用 test_input() 但未在显示的代码中定义。

2) 您的查询在 confirm_password 之后有额外的 ,

3) 插入查询将不起作用。有一些错误:

$query = "INSERT INTO customer (name,user_name, password,confirm_password, email) VALUES ('
$name', '$username', '$password', '$cpassword', '$email')";

4) 无需存储confirm_password

关于php - 我不知道为什么当我提交时isset函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45930986/

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