我在这里得到了我的代码。它在网络上工作,也在手机上,但只是通过safari/网络。如果它是作为一个链接打开有同样的错误。
<?php
header("Content-type: text/html; charset=utf-8");
$title = "Zapoj sa a vyhraj";
require("header.php");
$conn = new PDO('xxxxxxxxxxxxx');
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $conn->prepare('SELECT COUNT(*) AS `total` FROM sutaz_tabulka WHERE meno = :meno');
$meno = $_POST['meno'];
$sql->execute(array(':meno' => $meno));
$result = $sql->fetchObject();
if ($result->total > 0)
{
echo '<div class="dakujem" style="text-align: center; font-size: 30px; margin-top: 200px; padding: 50px 5px; color: white; background-color: rgb(220, 20, 60);">Nedávno ste sa už zapojili do našej súťaže!</div>';
}
else
{
$stmt = $conn->prepare("INSERT INTO sutaz_tabulka (meno) VALUES(:meno)");
$stmt->bindValue(':meno', $meno);
$stmt->execute(array(':meno' => $meno));
}
?>
我不知道该怎么解决。
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'meno' cannot be null' in /data/5/8/582bf4f8-549d-48a3-833c-52986c8a8ca5/zapojsavyhraj.sk/web/post-comment.php:30 Stack trace: #0 /data/5/8/582bf4f8-549d-48a3-833c-52986c8a8ca5/zapojsavyhraj.sk/web/post-comment.php(30): PDOStatement->execute(Array) #1 {main} thrown in /data/5/8/582bf4f8-549d-48a3-833c-52986c8a8ca5/zapojsavyhraj.sk/web/post-comment.php on line 30
1条答案
按热度按时间jucafojl1#
当你打开这个页面作为一个链接
$_POST['meno'];
必然是空的,它可以包含数据,如果你通过 AJAX 调用这个脚本因此,如果您想将此页面作为链接打开,则必须添加条件
if isset($_POST['meno']) or if !empty($_POST['meno']):