SQLに入力して入力するプリペアドステートメント私が得るのは、入力されたPHPアドレスを持つ空白のページだけです。私は何かを逃したのですか?私は下にコードを変更したが表示されるすべてはNULLです。日付フィールドはsql型の日付であり、テストするために入力した文字列は "2008-11-11"ですが、引用符はありません。 あなたのスクリプトの先頭に私は、SQLに入力して入力を印刷する必要があるプリペアドステートメントを持つ入力フォームを持っていますが、私はすべてページにNULLが印刷されています
error_reporting(E_ALL);
ini_set('display_errors', 1);
を追加し、適切な準備された文を使用します。
<?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>
mysqli_real_escape_string以下のコードで指摘し、我々は、フォームを見てみることができます –
あなたはプリペアドステートメントを使用した方法は間違っていますか? – Arthur
[PHPの死の白いスクリーン](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death)の可能な複製 – CBroe