0

我在 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();
}
?>
4

1 回答 1

0

在您的表单标签中有 2 个方法属性,应更正为;

<form action="connect.php" method="POST">  

而且在php代码中,mysqli连接应该是;

$conn = new mysqli('localhost','root','','first_db');  

其中四个参数分别是;

$conn= new mysqli("server name","username","password","database name");
于 2020-12-13T14:09:43.527 回答