Probleme virgules avec MySql

bobby
Invité n'ayant pas de compte PHPfrance

04 mars 2011, 21:14

Bonjour à tous, je poste ce forum à la suite d'un problème de virgule dans une base de donnée MySql :

J'ai deux page qui gèrent l'inscription à mon site :

inscription.php :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="fr" xml:lang="fr">
<head>
<script>
function countAdClick(id)
{
loadXMLDoc('./ads/click.php?a=' + id);
}

function countAdView(id)
{
loadXMLDoc('./ads/view.php?a=' + id);
}

function loadXMLDoc(url) {
req = false;
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.open("GET", url, true);
req.send(null);
}
}
</script>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" media="screen" type="text/css" title="style" href="css/style.css" />
<title>titre</title>
</head>
<?
include ("includes/fil.php");
include ("includes/head.php");
include("includes/menu.php");
include ("includes/bandeau.php");
?>

<div id="corps">
<h1>Inscription</h1>
<hr/>
<html>
<head>
</head>
<body>
<form action="inscription_confirmation.php" method="post">
<table id="inscription">
<tr>
<th>Nom</th>
<th><input type="text" name="nom" /></th>
</tr>
<tr>
<th>Prénom</th>
<th><input type="text" name="prenom" /></th>
</tr>
</table>
<table id="inscription">
<tr>
<th>Pseudo :</th>
<th><input type="text" name="login" /></th>
</tr>
<tr>
<th>Adresse mail :</th>
<td><input type="text" name="mail" /></td>
</tr>
<tr>
<th>Mot de passe :</th>
<th><input type="password" name="pass" /></th>
</tr>
</table><br/>
<br/>
<table id="inscription">
<th>Centre(s) d'interêt(s) :</th>
<td><input type="text" name="interets" /></td>
</tr>
<th>Occupation(s) :</th>
<td><input type="text" name="occupations" /></td>
</tr>
<th>Vos motivations :</th>
<td><input type="text" name="motivations" /></td>
</tr>
</table><br/>
<table id="inscription">
<th>Autres informations</th>
<td><textarea row="200" cols="60" name="informations"></textarea></td>
</tr>
</table>
<h2><input type="submit" name="inscription" value="Inscription"><a decoration="none" href="http://radiatorust.fr/" target=""><input type="button" value="Annuler"></a></h2>
</form>
<?php
if (isset($erreur)) echo '<br />',$erreur;
?>
</body>
</html>
et inscription_confirmation.php :
<?php
include ("includes/sql.php");
?>

<?php
ini_set('mysql.trace_mode', true);
error_reporting(E_ALL | E_STRICT);
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$login = $_POST['login'];
$mail = $_POST['mail'];
$pass = $_POST['pass'];
$interets = $_POST['interets'];
$occupations = $_POST['occupations'];
$motivations = $_POST['motivations'];
$informations = $_POST['informations'];

$sql = "INSERT INTO inscriptions (id, nom, prenom, login, mail, pass, interets, occupations, motivations, informations) VALUES ('', '$nom', '$prenom', '$login', '$mail', '$pass', '$interets', '$occupations', '$motivations, '$informations')";
$ret = mysql_query ($sql);
if ($ret === false) {
echo 'SQL error  (ligne '.__LINE__.') : '.mysql_error().'<br />with : '.$sql.'<br />';
}
mysql_close();
?>
Mais lorsque je rempli le formulaires, au moment de l'insertion dans la bdd une erreur apparaît :


Notice: Undefined variable: motivation in /var/www/bob-web.fr/htdocs/radiatorust/inscription_confirmation.php on line 19

Warning: mysql_query() [http://www.mysql.com/doc]: 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 1 in /var/www/bob-web.fr/htdocs/radiatorust/inscription_confirmation.php on line 20
SQL error (ligne 23) : 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 1
with : INSERT INTO inscriptions (id, nom, prenom, login, mail, pass, interets, occupations, motivations, informations) VALUES ('', 'Bob', 'Bob', 'Bob, '[email protected]', '', 'programmation, web, informatique', 'création de sites web', ', '')


Je ne pas vois d'erreur, j'ai cherché une solution à la "version de MySql" du message d'erreur mais j'ai rien trouvé. J'ai déjà fait des codes de st

devlop78
Invité n'ayant pas de compte PHPfrance

04 mars 2011, 21:27

Bizaremment, je ne vois pas la concordance entre ton code SQL et celui entré dans PHP. Mais l'erreur est flagrante ...

J'en profite pour conseiller l'emploi de NULL au lieu de '' pour l'identifiant si celui-ci est en auto-increment. En fait, je ne savais meme pas qu'on pouvait mettre une valeur vide, mais si ça marche, ce n'est qu'une tolérance.

Ensuite, je ne vois aucun échappement des données. Donc, il serait bien de lire un peu de docs sur PHP et MySQL et d'utiliser les échappements addéquats, bien qu'il soit fort possible que ton hébergeur utilise magic_quotes On.

Enfin, j'ai un doute sur un des deux codes :

VALUES ('', '$nom', '$prenom', '$login', '$mail', '$pass', '$interets', '$occupations', '$motivations, '$informations')";

VALUES ('', 'Bob', 'Bob', 'Bob, '[email protected]',

Comment $login peut être fermé d'un coté mais pas de l'autre ???
Je ne vois qu'une solution ... débug débug :p

kiorou
Invité n'ayant pas de compte PHPfrance

23 mai 2011, 11:43

"Notice: Undefined variable: motivation in /var/www/bob-web.fr/htdocs/radiatorust/inscription_confirmation.php on line 19"
je croi ke tu as oublier un ' apres $motivation dans ta requet sql

('', '$nom', '$prenom', '$login', '$mail', '$pass', '$interets', '$occupations', '$motivations, '$informations')";

Eléphant du PHP | 275 Messages

23 mai 2011, 12:11

Pas de quote fermant apres '$motivations