我在 html 表单中的提交按钮有这个问题,当我单击它而不是将表单详细信息发送到数据库时,它会在新窗口中显示 php 脚本,我已经尝试了所有我仍然无法工作的方法,请帮助html代码:
<!DOCTYPE html>
<html>
<head>
<title>sign up</title>
<link href="sign in.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<div class="signbox">
<h1>SIGN UP HERE</h1>
<form method="" action="connect.php" method="POST">
<p>First name:</p>
<input type="text" name="firstname" placeholder="enter your first name">
<p>Email address:</p>
<input type="text" name="email" placeholder="enter your email address">
<p>Password:</p>
<input type="password" name="password" placeholder="enter your password">
<p>Confirm password:</p>
<input type="password" name="password2" placeholder="confirm your password">
<input type="submit" value="sign in">
<a href="log in.html">already have an account?login here.</a>
</form>
</div>
</body>
</html>
PHP代码:
<?php
$firstname = $_POST['firstname'];
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
//database connection.
$conn = new mysqli('loacalhost','root','','','first_db');
if($conn->connect_error){
die('connection failed : '.$conn->connect_error);
}else{
$stmt = $conn->prepare("insert into users3(firstname, email, password, password2)
values(?, ?, ?, ?)");
$stmt->bind_param("ssss",$firstname, $email, $password, $password2);
$stmt->execute();
echo "registration complete...";
$stmt->close();
$conn->close();
}
?>