我试图让这个 PHP 代码与我的 html 一起工作。PHP 单独工作,但是当我尝试使用 html 表单并使用 PHP 代码时,它根本没有做任何事情。我一直试图弄清楚这一点,但没有任何成功。有人可以解释我做错了什么吗?
<?php
include_once("config.php");
if(isset($_POST['submit'])){
//Perform the verification
$uname = $_POST['uname'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
if($email == $email2){
if($pass == $pass2){
//All good. Carry on.
$query = $sql->prepare("INSERT INTO login (uname, email, pass) VALUES (?, ?, ?)");
$query->bind_param('sss', $uname, $email, $pass );
$query -> execute();
header("Location: index.html");
}else{
echo "Passwords do not match.<br />";
exit();
}
}else{
echo "Emails do not match.<br /><br />";
exit();
}
$sql->close();
$query->close();
}
?>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div class="container">
<section>
<div id="container_demo" >
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Username</label>
<input id="usernamesignup" name="usernamesignup" required="required" type="text"/>
</p>
<p>
<label for="emailsignup" class="email" data-icon="e"> Your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email"/>
</p>
<p>
<label for="emailsignup" class="email2" data-icon="e">Confirm your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email"/>
</p>
<p>
<label for="passwordsignup" class="pass" data-icon="p">Your password </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password"/>
</p>
<p>
<label for="passwordsignup_confirm" class="pass2" data-icon="p">Please confirm your password </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password"/>
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
<p class="change_link">
Already a member ?
<a href="index.html" class="to_register"> Go and log in </a>
</p>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>