2017-12-06 2 views
0

エラーPHP構文エラー。、SQL状態37000のSQLExecDirectで

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in E:\DEP\Prog\PHP6\starcraft\starcraft\personnage_traitement.php on line 61 [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

SQLクエリAjouterアクションを使用するときに(英語でADD)

$nom =$_POST["nom"]; 
$faction = $_POST["faction"]; 
$age = $_POST["age"]; 
$race = $_POST["race"]; 
$description = $_POST["description"]; 
$fichier = $_POST["image"]; 

if ($_POST["action"] == "Ajouter") { 


    $sql="Insert into personnage (nom, faction, race, age, description, image) values ('$nom', $faction, $race, $age,'$description', '$fichier')"; 


    odbc_exec($odbc, $sql) or die(odbc_error($odbc)); 

マイコード

<fieldset> 
    <legend>New hero</legend> 
        <label for="nom">Nom : </label><input type="text"  name="nom" id="nom" size="40" required><br> 
        <label for="age">Âge : </label><input type="number" name="age" id="age" size="40" required><br> 
        <label for="race">Race : </label><select name="race" id="race" size="1" > 
         <?php 
         $sql2 = "SELECT NomRace FROM Race;"; 
         $resultat2 = odbc_exec($odbc, $sql2) or die(odbc_error($odbc)); 

         odbc_fetch_row($resultat2, 0); 

         while (odbc_fetch_row($resultat2)) { 

          $idS = odbc_result($resultat2, "IDRace"); 

          $race = utf8_encode(odbc_result($resultat2, "NomRace")); 

          echo "<OPTION VALUE=\"$idS\">$race</OPTION>"; 
         } 
         ?> 
        </select> <a href="race.php">Édition des races</a><br> 
        <label for="faction">Faction : </label><select name="faction" id="faction" size="1" > 
         <?php 

         $sql3 = "SELECT NomFaction FROM Faction;"; 
         $resultat3 = odbc_exec($odbc, $sql3) or die(odbc_error($odbc)); 

         odbc_fetch_row($resultat3, 0); 

         while (odbc_fetch_row($resultat3)) { 

          $idS = odbc_result($resultat3, "IDFaction"); 

          $faction = utf8_encode(odbc_result($resultat3, "NomFaction")); 

          echo "<OPTION VALUE=\"$idS\">$faction</OPTION>"; 
         } 
         ?> 
        </select> <a href="faction.php">Édition des factions</a><br> 
        <label for="description">Description : </label><input type="text" name="description" id="description" size="40" required> 
        <br> 
        <br> 
        <input type="hidden" name="MAX_FILE_SIZE" value="100000"> 
        <label for="fichier">Fichier d'image : </label> 
        <input type="file" onchange="readURL(this);" name="fichier" id="fichier"> 
        <img alt="Image" id="preview" title="image" src="#" /> 
        <br> 
        <br> 
        <input type="submit" name="action" value="Ajouter"> 
       </fieldset> 
+2

作ることができ、この前に、SQLクエリが –

+0

oupsは私のコードの一部を忘れてしまった、完全に間違っている、サンプルコードです:申し訳ありませんO!このサイトで初めて質問をする! –

+0

あなたの質問を編集し、忘れてしまったコードを追加してください。誰もがあなたの問題を正しく理解するのに役立ちます。 –

答えて

0
<?php 
$nom =$_POST["nom"]; 
$faction = $_POST["faction"]; 
$age = $_POST["age"]; 
$race = $_POST["race"]; 
$description = $_POST["description"]; 
$fichier = $_POST["image"]; 

if ($_POST["action"] == "Ajouter") 
{ 
    $sql="INSERT into `personnage` SET `nom`='$nom',`faction`='$faction',`race`='$race',`age`='$age',`description`='$description',`image`='$fichier'"; 
    odbc_exec($odbc, $sql) or die(odbc_error($odbc)); 
} 

?> 
+0

ありがとう、それは働いた! –

+0

ようこそ:) @WilliamLeclerc –

0

これはあなたのif-elseブロック

if(condition) 
{ 

$sql = "INSERT INTO MyGuests (firstname, lastname, email) 
VALUES ('John', 'Doe', '[email protected]');" 

} 
+0

大丈夫ですよ、ありがとう! –

0
<?php 
$sql="INSERT INTO personnage(nom,faction,race,age,description,image)values('$nom','$faction','$race','$age','$description','$fichier')";odbc_exec($odbc,$sql)ordie(odbc_error($odbc)); 

or in mysql 

$sql=mysql_query("INSERT INTO personnage(nom,faction,race,age,description,image)values('$nom','$faction','$race','$age','$description','$fichier')")or die("Could not execute the insert query:".mysql_error()); 
?> 
+0

ありがとうございましたtho私は前に働くようになった:D –