[英]I am trying to create this login/registration form with validation
I am getting some sort of php error in my code but i am not sure what it is my code starts to get funny at the end when you get to the bottom php. 我的代码中出现某种php错误,但是我不确定这是什么,当您到达最底下的php时,我的代码在结尾时开始变得有趣。 I am trying to validate the username and password but iam getting some type of error 我正在尝试验证用户名和密码,但是却遇到某种类型的错误
<?php
include 'config.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Register Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="main-wrapper">
<center>
<h2 style="color: white;">Register Page</h2>
<img class="avatar" src="spaceman2.jpg" style="height: 100px; width: 100px" />
</center>
<form class="my-form" action="register.php" method="post">
<label><b>Username<b></label>
<input name="username" type="text" class="input-values" placeholder="Your username" required/>
<label><b>Password<b></label>
<input name="password" type="password" class="input-values" placeholder="Your password" required/>
<label><b>Confirm Password<b></label>
<input name="cpassword" type="password" class="input-values" placeholder="Confirm password" required/>
<input name="signup_btn" id="signup-btn" type="submit" value="Sign Up"/>
<br/>
<a href="login.php"><input id="back-btn" type="button" value="<- Back"/></a>
</form>
<?php
if(isset($_POST['signup_btn']))
{
//echo '<script type="text/javascript"> alert("You are now signed in!")</script>';
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['password'];
if($password == $cpassword)
{
$query= "SELECT * FROM user WHERE username ='$username'";
$query_run = mysqli_query($con,$query);
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript"> alert("Astronaut name already exist") </script>';
}
{
$query= "insert into user values('$username','$password')";
$query_run = mysqli_query($con, $query);
if($query_run)
{
echo '<script type="text/javascript"> alert("Astronaut is now registered! Go to Login Page!") </script>';
}
else
{
echo '<script type="text/javascript"> alert("Error!") </script>';
}
}
?>
A few things: 一些东西:
Your $cpassword is referencing your $_POST['password'] instead of cpassword. 您的$ cpassword引用了$ _POST ['password']而不是cpassword。
Your insert statement is missing the column references before your VALUES. 您的插入语句缺少VALUES之前的列引用。
You should also consider some password hashing / encryption. 您还应该考虑一些密码哈希/加密。
Your code has error because of 您的代码存在错误,原因是
specially in the php 特别是在PHP
you forgot else
and you used password
for $cpasswrod
您忘记了else
并使用了$cpasswrod
password
in html
you don't close </b>
在html
您不会关闭</b>
<?php
include 'config.php';
if(isset($_POST['signup_btn']))
{
//echo '<script type="text/javascript"> alert("You are now signed in!")</script>';
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if($password == $cpassword){
$query= "SELECT * FROM user WHERE username ='$username'";
$query_run = mysqli_query($con,$query);
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript"> alert("Astronaut name already exist") </script>';
}
else{
$query= "insert into user values('$username','$password')";
$query_run = mysqli_query($con, $query);
if($query_run)
{
echo '<script type="text/javascript"> alert("Astronaut is now registered! Go to Login Page!") </script>';
}
else
{
echo '<script type="text/javascript"> alert("Error!") </script>';
}
}
}
}
?>
<html>
<head>
<title>Register Page</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="main-wrapper">
<center>
<h2 style="color: white;">Register Page</h2>
<img class="avatar" src="spaceman2.jpg" style="height: 100px; width: 100px" />
</center>
<form class="my-form" action="index.php" method="post">
<label><b>Username</b></label>
<input name="username" type="text" class="input-values" placeholder="Your username" required/>
<label><b>Password</b></label>
<input name="password" type="password" class="input-values" placeholder="Your password" required/>
<label><b>Confirm Password</b></label>
<input name="cpassword" type="password" class="input-values" placeholder="Confirm password" required/>
<input name="signup_btn" id="signup-btn" type="submit" value="Sign Up"/>
<br/>
<a href="login.php"><input id="back-btn" type="button" value="<- Back"/></a>
</form>
</div>
</body>
</html>
I hope it helps 希望对您有所帮助
Here is a new version of your code: (Try it) 这是您的代码的新版本:(尝试)
<?php
include 'config.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Register Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="main-wrapper">
<center>
<h2 style="color: white;">Register Page</h2>
<img class="avatar" src="spaceman2.jpg" style="height: 100px; width: 100px" />
</center>
<form class="my-form" action="register.php" method="post">
<label><b>Username</b></label>
<input name="username" type="text" class="input-values" placeholder="Your username" required />
<label><b>Password</b></label>
<input name="password" type="password" class="input-values" placeholder="Your password" required />
<label><b>Confirm Password</b></label>
<input name="cpassword" type="password" class="input-values" placeholder="Confirm password" required />
<input name="signup_btn" id="signup-btn" type="submit" value="Sign Up"/>
<br/>
<a href="login.php"><input id="back-btn" type="button" value="<- Back"/></a>
</form>
<?php
if(isset($_POST['signup_btn']))
{
//echo '<script type="text/javascript"> alert("You are now signed in!")</script>';
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if($password == $cpassword)
{
$query= "SELECT * FROM user WHERE username ='$username'";
$query_run = mysqli_query($con,$query);
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript"> alert("Astronaut name already exist") </script>';
}else
{
$query= "insert into user (username, password) values('$username','$password')";
$query_run = mysqli_query($con, $query);
if($query_run)
{
echo '<script type="text/javascript"> alert("Astronaut is now registered! Go to Login Page!") </script>';
}
else
{
echo '<script type="text/javascript"> alert("Error!") </script>';
}
}
}
}
?>
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.