我的网站上有一个表单,将数据提交到我的(mysql)数据库。这是通过Mysqli完成的。提交表格后,我收到消息:
"inputoftextboxhere"已被添加到数据库中!。
但是当我查看我的数据库时,只有值为 0。
插入.php
<?php
//config bestand ophalen.
require_once 'config.php';
if(isset($_POST['submit']))
{
$email = $mysqli->real_escape_string($_POST['email']);
$sql = "INSERT INTO maillist (id, email) VALUES ('', '$email')";
if ($mysqli->query($sql))
{
echo "<center><div class='alert alert-success' role='alert'>".$email." is succesvol toegevoegd aan de database!</div></center>";
}
else
{
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
$mysqli->close();
}
?>
索引.php
<form action="insert.php" method="post" accept-charset="utf-8" class="form" name="submit">
<legend>Email </legend>
<input type="text" name="email" value="" class="form-control input-lg" placeholder="E-mail" /><br />
<button class="btn btn-lg btn-primary btn-block signup-btn" name="submit" type="submit">Voeg nummer toe</button>
</form>
数据库截图:https://gyazo.com/9ec48d3ce4ec6643d8fbcb2f3db42052
请确保数据库表中电子邮件列的数据类型为文本或 varchar。如果它设置为整数或双精度,这可能是问题所在。
确保数据库可以存储字符串,因此请选择 Varchar。当它设置得太布尔/位或任何基于数字的数据类型时,您的数据库现在不知道如何处理字符串输入。否则,请调试要发布的值,以确保不只是在数据库中放置零。