PHP提交显示空白页面

时间:2014-03-20 19:40:11

标签: php forms

我已经为用户创建了一个表单,用于提交添加到数据库的信息,但是当我单击提交按钮时,submit.php显示为空白,我认为这意味着存在某种形式的错误。我自己找不到任何错误,希望有人可以。

<?php
$con=mysqli_connect("localhost","tyler1996","Tylerkernick1996","essays");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO essays (author, email, essaytitle, subject, examboard, essay)
VALUES
       ('$_POST[author]','$_POST[subject]','$_POST[essaytitle]','$_POST[subject]','$_POST[examboard]','$_POST[essay]')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?> 

2 个答案:

答案 0 :(得分:0)

您可能遇到的错误是将$_POST['whatever']直接嵌入字符串中。您还没有引用$ _POST数组的键。正如@Fabio所说,你也很容易受到注射,你需要打开错误报告,这会告诉你所有这些事情。如果您使用的是apache,this可能有所帮助。它会在某个php.ini文件中出现。

答案 1 :(得分:0)

add these two lines to the top of your php file:
ini_set("display_errors","on");
error_reporting(E_ALL && ~E_NOTICE);


Also add exit after the mysqli connection failure echo.

And then you need to quote the keys in the $_POST array like this :$_POST[\"subject\"]

Do all of these and then let us know what is the result.