简体   繁体   中英

insert into database error SQLSTATE[HY093]

i have been on the busy with this script to save the data from this form

the connect.php sets up my connection to the database

(sorry for the dutch comments in between the code)

 <?php
 include('connect.php');
 //Gebruik de method ->exec(). Raadpleeg de reader hoe je deze method moet gebruiken. 

 $KijkerV =$_POST['KijkerV'];
 $KijkerT_V =$_POST['KijkerT_V']; 
 $KijkerA=$_POST['KijkerA'];
 $Email = $_POST['Email'];
  $ShowId = $_POST['ShowId'];

 try { 

  $sql = 'INSERT INTO tblkijker (Kijkerv, KijkerT_V, KijkerA, Email, ShowId) 
  VALUES (:Kijkerv, :KijkerT_V, :KijkerA, :Email, :ShowId'; 

  //het statement wordt toegevoegd aan een pdo statement object 
  $s = $pdo->prepare($sql); 
  //koppelen van parameters in de query string met de te inserten waardes 
  $s->bindValue(':Kijkerv', $KijkerV, PDO::PARAM_STR); 
  $s->bindValue(':KijkerT_V', $KijkerT_V, PDO::PARAM_STR);
  $s->bindValue(':KijkerA', $KijkerA, PDO::PARAM_STR);
  $s->bindValue(':Email', $Email, PDO::PARAM_STR);    
  $s->bindValue(':ShowId', $ShowId, PDO::PARAM_STR);

  var_dump($KijkerV);
 var_dump($KijkerT_V);
 var_dump($KijkerA);
 var_dump($Email);
 var_dump($ShowId);
 var_dump($sql);
 var_dump($S);
  //Nu kan de query worden uitgevoerd 
  $s->execute(); 
  //id is een auto_increment veld is nu bepaald 
  $Stoelnummer = $pdo->lastInsertId(); 
  $output = "Uw kaarten zijn gereseveerd u heeftb stoelnummer: ".$Stoelnummer; 

 } 
 catch (PDOException $e) 
 { 
  $output = 'Fout bij inserten van een rij: ' . $e->getMessage(); 
 } 
?> 
<html> 
 <head></head> 
 <body> 
 <?php echo $output ?> 
 </body> 
</html>

the error that is making its appearance: Fout bij inserten van een rij: (as set with the catch)

 error 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 '' at line 2

what has gone wrong here?

You seem to not close the parantheses.

This:

$sql = 'INSERT INTO tblkijker (Kijkerv, KijkerT_V, KijkerA, Email, ShowId) 
VALUES (:Kijkerv, :KijkerT_V, :KijkerA, :Email, :ShowId';

Should be

$sql = 'INSERT INTO tblijker (Kijkerv, KijkerT_V, KijkerA, Email, ShowId)
VALUES (:Kijkv, :KijkerT_V, :KijkerA, :Email, :ShowId)';

This should probably fix the error you're getting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM