html表单+php+mysql 500错误

dy1byipe  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(267)

我收到一个内部错误时,试图插入数据从html格式到mysql数据库通过php。我在ubuntu服务器上用apache2webserver(droplet使用digitalocean)托管一个站点。php和mysql都安装在服务器上。下面是html和php。我已经用变量$name的php echo进行了测试,这是成功的,但是每当我尝试连接到mysql时就会抛出错误。我知道500是一个内部错误,但不知道从这里去哪里。

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">

<head>
    <title>who this</title>
    <link rel="stylesheet" type="text/css" href="STYLE.css">
</head>

<body>
    <h1 id="header2">me</ h1>

    <div id="back">
            <a href="/index.html">back</a>
    </div>

    <div id="me-intro">
        <p>tell me about yourself</p>
    </div>

    <div id="joke">
    <form action="process.php" method="POST">
        <div id="one">
            <p>name: <input type="text" name="name" id='first'></p>
        </div>
        <div id="two">
            <p>gender: <input type="text" name="gender" id='second'></p>
        </div>
        <div id="three">
            <p>age: <input type="text" name = "age" id='third'></p>
        </div>
        <div id="four">
            <p>occupation: <input type="text" name="occupation" id='fourth'></p>
        </div>
        <div id="five">
            <p>education: <input type="text" name="education" id='fifth'></p>
        </div>
        <div id="six">
            <p>car you drive: <input type="text" name="car" id='sixth'></p>
        </div>
        <div id="seven">
            <p>phone number: <input type="text" name="phone" id="seventh"></p>
        </div>
        <div id="eight">
            <p>address: <input type="text" name="address" id="eighth"></p>
        </div>
        <div id="nine">
            <p>social security number: <input type="text" name="ssn" id="ninth">
        </div>
        <div id="ten">
            <input type="submit">
        </div>
    </form>
    </div>
</body>

</html>

下面是process.php

<?php

$conn = new mysqli("localhost", "root", "password_here", "database_here");

$name = $_POST["name"];
$gender = $_POST["gender"];
$age = $_POST["age"];
$occupation = $_POST["occupation"];
$education = $_POST["education"];
$car = $_POST["car"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$ssn = $_POST["ssn"];

if($conn -> connect_error) {
    die("err: dis not working: " . $conn->connect_error);
}

$sql = "INSERT INTO table_here (name, gender, age, occupation, education, car, phone, address, ssn) VALUES ('$name', '$gender', '$age', '$occupation', '$education', '$car', '$phone', '$address', '$ssn')";

if($conn->query($sql) === TRUE){
    echo "success";
} else {
    echo "error: did not submit form to mysql";     
}
$conn->close();
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题