我试图在我的SQL表中注册用户在表单中输入的电子邮件。但是我没有收到任何错误,也没有保存数据!
<?php
echo "I was here !!!";
if(!empty($_POST['mail']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mailing";
echo "I was here !!!";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = 'INSERT INTO contact VALUES ("","'.$_POST['mail'].'")';
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
和我的HTML代码:
<div class="form">
<p>Rester notifié par toutes les nouveautés !</p>
<form method="post" action="index.php" class="mainform">
<div class="field"><input type="text" class="field" name="mail" /></div>
<div class="submit"><input class="submit" type="button" value="Envoyer" /></div>
</form>
</div>
你可以告诉我这个问题是什么吗?
答案 0 :(得分:0)
更改您的按钮类型。因为如果您想通过表单提交数据,那么按钮类型应该像那样提交
<input class="submit" type="submit" value="Envoyer" />
答案 1 :(得分:0)
检查$ _POST [&#39; mail&#39;]是否有值。你的条件并没有为$ _POST [&#39; mail&#39;]处理空值。如果有价值。更改您的查询
INSERT INTO contact(email) VALUES ("'.$_POST['mail'].'")
试试这个。因为您只需要添加电子邮件。希望它有所帮助。