2017-06-07 12 views
-1

我有一個輸入形式與一個預先準備好的語句,應該輸入到sql和打印輸入,但我得到的只是輸入p​​hp地址的空白頁面。我錯過了什麼?我已將代碼更改爲下方,但所有顯示的都是NULL。日期字段是sql類型的日期,我輸入它來測試的字符串是「2008-11-11」,當然沒有引號。我有一個輸入表格應該輸入到sql並打印輸入,但我得到的是NULL打印在頁面上

 <?php 
function shutdown(){ 
    var_dump(error_get_last()); 
} 

register_shutdown_function('shutdown'); 
session_start(); 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 
include("dbconfig.php"); 
$errorvar = ""; 
if (isset($_POST['submit'])) { 
    if (empty($_POST['Title']) || empty($_POST["Date"]) || empty($_POST["Country"]) || empty($_POST["bloguser"]) || empty($_POST["Blogentry"])) { 
     $errorvar = "You dun gooffed"; 
     echo $errorvar; 
    } else { 
     //defining and injection protecting data 
     $title = $_POST['Title']; 
     $date = $_POST['Date']; 
     $country = $_POST['Country']; 
     $bloguser = $_POST['bloguser']; 
     $blogentry = $_POST['Blogentry']; 

    $stmt = $mysqli->prepare("INSERT INTO blogs (BlogName,blogDate,country,bloguser,Blogdata) VALUES (?,?,?,?,?)"); 

     $stmt->bind_param('sssss', $title, $date, $country, $bloguser, $blogentry); 

     if ($stmt->execute()) { 
      echo "New records created successfully"; 
      printf("%d Row inserted.\n", $stmt->affected_rows); 
      header("location:index.php"); 
     } else { 
     header("location:index.php"); 
      echo $conn->error; 
     } 
     $stmt->close(); 
     $conn->close(); 
     header("location:index.php"); 
    } 
} 
?> 

HTML表單低於

<fieldset style="width:45%"><legend>Blog data entry</legend> 
     <form name="Blogentry" action="Inputform.php" method="POST"> 
      <label for="Title">Title: </label> 
      <input type="text" name="Title" value="" size="40"/><br> 
      <label for="Date">Date: </label> 
      <input type="text" name="Date" value="" size="40"/><br> 
      <label for="Country">Country: </label> 
      <input type="text" name="Country" value="" size="40"/><br> 
      <label for="bloguser">User: </label> 
      <input type="text" name="bloguser" value="" size="40"/><br> 
      <label for="Blogentry">Blog: </label> 
      <textarea name="Blogentry" rows="4" cols="20"> 
      </textarea><br> 
      <input id="button" type="submit" name="submitblog" value="submit-blog"> 
     </form> 
      </fieldset> 
    </body> 
</html> 
+0

mysqli_real_escape_string代碼指出將返回空,如果mysqli的連接是無效的,而你使用準備好的語句的方式是不正確 –

+0

我們可以看一看的形式? – Arthur

+0

[PHP的死亡白屏]可能的重複(https://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – CBroe

回答

0

啓用錯誤報告: 在上面添加腳本

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

,然後用準備好的語句正確。至於你的腳本有沒有參數所綁定,

<?php 
session_start(); 
include("dbconfig.php"); 
$errorvar = ""; 
if (isset($_POST['submit'])) { 
    if (empty($_POST['Title']) || empty($_POST["Date"]) || empty($_POST["Country"]) || empty($_POST["bloguser"]) || empty($_POST["Blogentry"])) { 
     $errorvar = "You dun gooffed"; 
     echo $errorvar; 
    } else { 
     //defining and injection protecting data 
     $title  = $_POST['Title']; 
     $date  = $_POST['Date']; 
     $country = $_POST['Country']; 
     $bloguser = $_POST['bloguser']; 
     $blogentry = $_POST['Blogentry']; 

     $stmt = $conn->prepare("INSERT INTO blogs (BlogName,blogDate,country,bloguser,Blogdata) VALUES (?,?,?,?,?)"); 

     $stmt->bind_param("sssss", $title, $date, $country, $bloguser, $blogentry); 

     if ($stmt->execute()) { 
      echo "New records created successfully"; 
      printf("%d Row inserted.\n", $stmt->affected_rows); 
      header("location:index.php"); 

     } else { 

      echo $conn->error; 
     } 
     $stmt->close(); 
     $conn->close(); 
    } 
} 
?> 
0

你不需要逃避什麼,因爲您使用綁定 所以滴在你的查詢mysqli_real_escape

你有錯誤,因爲我下面

$stmt = $mysqli->prepare("INSERT INTO blogs (BlogName,blogDate,country,bloguser,Blogdata) VALUES (?,?,?,?,?)"); 
    // question marks will be replaced with data - use question marks! 
     $stmt->bind_param('sssss', $title, $date, $country, $bloguser, $blogentry); 
    // number of bound parameters should match number and order of question marks 

     $stmt->execute();