INSERT INTO 语句中的 PHP 语法错误。SQLExecDirect 中的 SQL 状态 37000

标签 php html mysql sql sql-server

错误

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.

使用 Ajouter 操作时的 SQL 查询(英文为 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>  

最佳答案

<?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));
}

?>

关于INSERT INTO 语句中的 PHP 语法错误。SQLExecDirect 中的 SQL 状态 37000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47667517/

相关文章:

php - 使用 mysql_real_escape_string 清理我的查询

mysql - 如何在 MySQL 中返回数据透视表输出?

mysql - 用最少的时间总和获得最多的用户分数

php - 多行验证

php - 传递给 Y 的参数 X 必须是 bool 值的实例, bool 值给定 - PHP7

javascript - 使用 JavaScript 将 HTML 内容附加到 div 的最快方法

Javascript 用逗号添加数字

html - 使用 CSS 到 'pop-out' div 列表中的一个 div

mysql - 如何从 MySQL 打印消息以进行调试?

php - 如何获取要下载的文件的 MIME 类型?