php - 500 (Internal Server Error) on jQuery POST -
am sending post request jquery lib php script, you'll find scripts below. i'm getting 500 internal server error result, know how fix it?
how send form:
$.post( "post.php", $( "#form" ).serialize() ).done(function( data ){ generatefinishpage( data.link ); });
my post.php
<?php error_reporting(e_all); ini_set("display_errors", 1); $pdo = new pdo('...'); $error = array(); if(empty($_post['link'])) $error [] = 'er geen link geselecteerd!'; if(empty($_post['sitename'])) $error [] = 'er geen domein geselecteerd!'; if(empty($_post['image'])) $error [] = 'er geen image geselecteerd!'; $selectquery = $pdo->query('select * trolls url_text="' . $_post['url'] . '" , url_domein="' . $_post["sitename"] . '"'); if($selectquery->rowcount() == 1) $error [] = 'dezelfde link bestaat al!'; if(count($error) == 0){ $query = $pdo->query('insert 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;
the form data sent:
sitename:lnstagram.nl
link:test
image:anne
creator_name:test
creator_email:test@test.nl
creator_text:test
thanks!
check select query.... "url_domein" or "url_domain"?
what trying in insert method?
i couldnt see prepared statements have called execute method?
$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'] ) );
try change query this... use prepare
$query = $pdo->prepare('insert 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)');
use try catch block query know error
try { // query here } catch (pdoexception $pe) { die("error:" . $pe->getmessage()); }
Comments
Post a Comment