如何通过POST从html发送数据到php

时间:2019-05-28 10:57:15

标签: php html database post

我使用html创建了简单的注册表单,而不是我试图通过POST将数据从表单发送到php文件并将数据填充到数据库中。填充数据有效,但是数据库中的新记录为空。我在做什么错了?

我试图将php代码与表单放在同一文件中,更改GET上的POST。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" href="Style/style.css" type="text/css"/>
</head>
<body>
    <div id="container">
        <form method="post" action="signup.php">
            <input name="name" class="control" type="text" placeholder="Imie" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Imie'" />
            <input name="surname" class="control" type="text" placeholder="Nazwisko" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Nazwisko'"/>
            <input name="phone" class="control" type="text" placeholder="Nr telefonu" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Nr telefonu'"/>
            <input name="email" class="control" type="email" placeholder="Email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email'"/>
            <input name="date" class="control" type="date" />
            <input name="time" class="control" type="time" />
            <select name="service"  class="control">
                <option>Test1</option>
                <option>Test2</option>
                <option>Test3</option>
                <option>Test4</option>
            </select>
            <br />
            <input name="record" id="record" type="submit" value="Zapisz się !">  
        </form>  
    </div>
</body>
</html>
<?php
    $db = mysqli_connect('localhost', 'root', '', 'test');
    $name = $_POST['name'];
    $surname = $_POST['surname'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $date = $_POST['date'];
    $time = $_POST['time'];
    $service = $_POST['service'];
    $query = "INSERT INTO 'test' ('name','surname','phone','email','date','time','service') VALUES ('$name','$surname','$phone','$email','$date','$time','$service');"
    mysqli_query($db, $query);
?>

0 个答案:

没有答案