error in your SQL syntax - formulaire INSERT INTO
Posté : 30 avr. 2009, 11:18
Bonjour,
Je suis en train de créer un site de e-commerce de vêtements mais j'ai un soucis avec l'insertion de la valeur du stock de chaque taille pour 1 produit.
J'ai une table produit et une autre pour les tailles. Les champs de la table "taille" sont "id", "produitid", "36", "38", "40", "42".
Voici l'erreur affichée : "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 '36, 38, 40, 42) VALUES (30, 6, 5, 2, 8)' at line 1". (Le "30" correspond à l'id du produit, 6,5,2 et 8 aux quantités en stock de chaque taille.)
Voici mon formulaire pour insérer le stock de chaque taille.
Voici le code qui se trouve au dessus du doctype :
Je n'arrive pas à comprendre pour la valeur de "produitid" n'est pas attendue. Si quelqu'un peut m'expliquer ou me dire quelle est mon erreur ça m'aiderait beaucoup.
Je suis en train de créer un site de e-commerce de vêtements mais j'ai un soucis avec l'insertion de la valeur du stock de chaque taille pour 1 produit.
J'ai une table produit et une autre pour les tailles. Les champs de la table "taille" sont "id", "produitid", "36", "38", "40", "42".
Voici l'erreur affichée : "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 '36, 38, 40, 42) VALUES (30, 6, 5, 2, 8)' at line 1". (Le "30" correspond à l'id du produit, 6,5,2 et 8 aux quantités en stock de chaque taille.)
Voici mon formulaire pour insérer le stock de chaque taille.
Code : Tout sélectionner
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">produit</td>
<td><input name="produitid" type="text" id="produitid" value="<?php echo $row_produit['id']; ?> " />
<?php echo $row_produit['nom_marque_produit']?> <?php echo $row_produit['modele']?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">stock taille 36</td>
<td><input name="36" type="text" id="36" value="0" size="2" maxlength="2" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">stock taille 38</td>
<td><input name="38" type="text" id="38" value="0" size="2" maxlength="2" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">stock taille 40</td>
<td><input name="40" type="text" id="40" value="0" size="2" maxlength="2" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">stock taille 42</td>
<td><input name="42" type="text" id="42" value="0" size="2" maxlength="2" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insérer un enregistrement" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form><?php require_once('../Connections/xxx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO taille (produitid, 36, 38, 40, 42) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['produitid'], "int"),
GetSQLValueString($_POST['36'], "int"),
GetSQLValueString($_POST['38'], "int"),
GetSQLValueString($_POST['40'], "int"),
GetSQLValueString($_POST['42'], "int"));
mysql_select_db($database_xxx, $xxx);
$Result1 = mysql_query($insertSQL, $xxx) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_produit = "-1";
if (isset($_GET['id'])) {
$colname_produit = $_GET['id'];
}
mysql_select_db($database_xxx, $xxx);
$query_produit = sprintf("SELECT id, nom_marque_produit, modele FROM produit WHERE id = %s", GetSQLValueString($colname_produit, "int"));
$produit = mysql_query($query_produit, $xxx) or die(mysql_error());
$row_produit = mysql_fetch_assoc($produit);
$totalRows_produit = mysql_num_rows($produit);
?>
Version du client MySQL: 5.0.51aJe n'arrive pas à comprendre pour la valeur de "produitid" n'est pas attendue. Si quelqu'un peut m'expliquer ou me dire quelle est mon erreur ça m'aiderait beaucoup.