我发送一个带有jQuery lib的POST请求到PHP脚本,你会发现下面的脚本。我收到500内部服务器错误,有人知道如何修复它吗?
我如何发送表单:
$.post(
"post.php",
$( "#form" ).serialize()
).done(function( data ){
generateFinishPage( data.link );
});
我的帖子.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$pdo = new PDO('...');
$error = Array();
if(empty($_POST['link']))
$error [] = 'Er is geen link geselecteerd!';
if(empty($_POST['sitename']))
$error [] = 'Er is geen domein geselecteerd!';
if(empty($_POST['image']))
$error [] = 'Er is geen image geselecteerd!';
$selectQuery = $pdo->query('SELECT * FROM trolls WHERE url_text="' . $_POST['url'] . '" AND url_domein="' . $_POST["sitename"] . '"');
if($selectQuery->rowCount() == 1)
$error [] = 'Dezelfde link bestaat al!';
if(count($error) == 0){
$query = $pdo->query('INSERT INTO trolls (created_time, swf_theme, url_text, url_domain, creator_ip, creator_name, creator_text, creator_email)
VALUES (:created_time, :swf_theme, :url_text, :url_domain, :creator_ip, :creator_name, :creator_text, :creator_email)');
$query->execute(
array(
':created_time' => date('d-m-o'),
':swf_theme' => $_POST['image'] . ".swf",
':url_text' => explode('/', $_POST['url'])[1],
'url_domain' => explode('/', explode(".", $_POST['url'])[1])[0],
':creator_ip' => $_SERVER['REMOTE_ADDR'],
':creator_name' => $_POST['creator_name'],
':creator_text' => $_POST['creator_text'],
':creator_email' => $_POST['creator_email']
)
);
echo json_encode(array("link" => $_POST['url']));
} else {
echo json_encode(array("link" => array($error));
}
$pdo = null;
发送的表单数据:
sitename:lnstagram.nl
link:test
图像:安
CREATOR_NAME:测试
creator_email:test@test.nl
creator_text:测试
谢谢!
答案 0 :(得分:2)
检查您的选择查询....是“url_domein”还是“url_domain”?
您在插入方法中尝试做什么?
我看不到任何准备好的语句但你调用了execute方法吗?
$query->execute(
array(
':created_time' => date('d-m-o'),
':swf_theme' => $_POST['image'] . ".swf",
':url_text' => explode('/', $_POST['url'])[1],
'url_domain' => explode('/', explode(".", $_POST['url'])[1])[0],
':creator_ip' => $_SERVER['REMOTE_ADDR'],
':creator_name' => $_POST['creator_name'],
':creator_text' => $_POST['creator_text'],
':creator_email' => $_POST['creator_email']
)
);
尝试更改此类查询...使用准备
$query = $pdo->prepare('INSERT INTO trolls (created_time, swf_theme, url_text, url_domain, creator_ip, creator_name, creator_text, creator_email)
VALUES (:created_time, :swf_theme, :url_text, :url_domain, :creator_ip, :creator_name, :creator_text, :creator_email)');
使用try catch block进行查询以了解错误的位置
try {
// query here
} catch (PDOException $pe) {
die("Error:" . $pe->getMessage());
}
答案 1 :(得分:0)
直接访问你的post.php,你会发现真正的错误。并且不要忘记在yor post.php
的顶部显示错误 error_reporting(E_ALL); nullini_set('display_errors', '1');