【发布时间】:2019-08-07 20:31:27
【问题描述】:
我想在使用 phpMyAdmin 设置的数据库中传递以下表单的值:
<form action="recordBook.php" method="post">
<input type="text" name="title" placeholder="Enter the book title">
<input type="text" name="author" placeholder="Enter the author's name">
<input type="checkbox" name="read" value="1">
<br><input type="submit">
</form>
当我没有传递最后一个变量 $read 时,下面的 php 可以正常工作。每当我通过 $read 时,都会引发 SQL 语法错误。我尝试了多个变体来替换 1 和 0:true、TRUE 等,但没有得到肯定的结果。在我的数据库中,“读取”列设置为 tinyint
<?php
include "db_connect.php";
$title = $_POST['title'];
$author = $_POST['author'];
$read = isset($_POST['read']) ? 1 : 0;
echo "<script>console.log('".$title.$author.$read."');</script>";
$sql=("INSERT INTO books (title,author_name, read) VALUES ('$title','$author', '$read')");
if ($mysqli->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
?>
有人知道可能导致此错误的原因吗?
【问题讨论】:
标签: php sql forms phpmyadmin boolean