PHP/MySQL文本到数据库表 - 查询命中但文本为空
问题描述:
不太确定我要出错的地方。我需要对文本进行编码吗?当我作为测试回应时,它工作正常。数据库也正在被使用。但是当查询命中时,没有文本。PHP/MySQL文本到数据库表 - 查询命中但文本为空
<?php
include($_SERVER['DOCUMENT_ROOT'].'/includes/dbh.php');
$newNote = mysqli_real_escape_string($conn, $_POST['note']);
if (empty($newNote)){
header("Location: /admin/notes.php?error=empty");
exit();
} else {
$sql = "INSERT INTO notes (note) VALUES ('$NewNote')";
$result = mysqli_query($conn, $sql);
header("Location: /admin/notes.php?success");
}
?>
<div class="section">
<div class="container">
<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strpos($url, 'error=empty') !== false) {
echo "<div class='alert alert-danger'>Error: You must enter some text!</div>";
}
elseif (strpos($url, 'success') !== false) {
echo "<div class='alert alert-success'>Note successfully submitted!</div>";
}
?>
<h3>Add Note</h3>
<form action="/admin/includes/notes.inc.php" method="post">
<div class="form-group">
<textarea name="note" class="form-control m20" rows="5"></textarea>
<button type="submit" name="submit" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Submit</button>
</div>
</form>
</div>
</div>
答
PHP中的变量区分大小写。
您只需将查询插入行中的$ NewNote变量的第一个“N”小写,它应该可以工作。
我的天啊。谢谢,愚蠢的小错误。 – Evan