2017-02-14 57 views
0

不太確定我要出錯的地方。我需要對文本進行編碼嗎?當我作爲測試迴應時,它工作正常。數據庫也正在被使用。但是當查詢命中時,沒有文本。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> 

回答

2

PHP中的變量區分大小寫。
您只需將查詢插入行中的$ NewNote變量的第一個「N」小寫,它應該可以工作。

+0

我的天啊。謝謝,愚蠢的小錯誤。 – Evan