2017-01-16 5 views
0

Im Anschluss an mein Code, $data[0]->persinId von AngularJS POST-Anfrage übergebenPHP MYSQL Syntaxfehler oder Zugriffsverletzung: 1064

$idPerson=$data[0]->persinId; 
$StmtQuestionType=connect_db()->query('SELECT a.`question_id` FROM answer a WHERE a.`person_id`=:PersonId'); 
$StmtQuestionType->bindValue(':PersonId',$idPerson); 
$StmtQuestionType->execute(); 

aber ich bin nach immer err

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':PersonId' at line 1' in C:\xampp\htdocs\survey\insert.php:11 Stack trace: #0 C:\xampp\htdocs\survey\insert.php(11): PDO->query('SELECT a.`quest...') #1 {main} thrown in C:\xampp\htdocs\survey\insert.php on line 11 
+0

'prepare' statt' query'? – emaillenin

+0

'query()' führt die angegebene Abfrage sofort aus. Stattdessen möchten Sie 'prepare()', dann 'bind()', dann 'execute()' ... verwenden – arkascha

+0

Replace '$ StmtQuestionType = connect_db() -> query ('SELECT a.'question_id' FROM Antwort a WHERE a.person_id': PersonId '); 'with' StmtQuestionType = connect_db() -> prepare (' SELECT a.'question_id' FROM Antwort eines WHERE a.person_id' =: PersonId '); ' –

Antwort

2

sollten Sie ersetzen:

$StmtQuestionType=connect_db()->query('SELECT a.`question_id` 
           FROM answer a WHERE a.`person_id`=:PersonId'); 

mit:

$StmtQuestionType=connect_db()->prepare('SELECT a.`question_id` 
           FROM answer a WHERE a.`person_id`=:PersonId'); 

Sie mussten zuerst "vorbereiten", nicht "abfragen", da Sie eine vorbereitete Anweisung mit benannten Platzhaltern verwenden.

Verwandte Themen