elstef
Mar 10 2005, 12:46 PM
J'ai monté un script séparé en plusieurs pages, proposant pour certaines la modification de données,
le formulaire de modification va chercher les données d'affichage sur une autre page
j'ai le message suivant :
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in mon site on line 22
l'erreur est situé a la ligne
if( $result = mysql_fetch_object( $requete )
de la page : modification
voici les paramêtre de recup de variables
<?php
//connection au serveur
$connex = mysql_connect( "localhost", "elstef", "n.net" ) ;
//sélection de la base de données:
$db = mysql_select_db( "versus" ) ;
//récupération de la variable d'URL,
//qui va nous permettre de savoir quel enregistrement modifier
$id = $_GET["idpromotion"] ;
//requête SQL:
$sql = "SELECT * FROM promotions WHERE id_promotion = ".$id ;
//exécution de la requête:
$requete = mysql_query( $sql, $connex ) ;
//affichage des données, la ou il y a une erreur:
if( $result = mysql_fetch_object( $requete ) )
{
?>
<form name="insertion" action="op_modification.php" method="POST">
<!---------------------------------------------------------------------------------------------------->
<!-- champ caché qui va nous servir à 'sauvegarder' l'identifiant de la personne -->
<input TYPE="hidden" name="id" value="<?php echo($id) ;?>">
<!---------------------------------------------------------------------------------------------------->
<table border="0" align="center" cellspacing="2" cellpadding="2">
<tr align="center" valign="top">
<td align="left">Promotion</td>
<td align="left">
<input type="text" name="promotion" value="<?php echo($result->promotion) ;?>">
</td>
</tr>
<tr align="center" valign="top">
<td align="left">description</td>
<td align="left">
<textarea name="description" type="text" cols="60" rows="12" id="description" value="<?php echo($result->description) ;?>"></textarea>
</td>
</tr>
<tr align="center" valign="top">
<td align="left">Prix</td>
<td align="left">
<input type="text" name="prix" value="<?php echo($result->prix) ;?>">
</td>
</tr>
<tr align="center" valign="top">
<td align="left">Photo</td>
<td align="left">
<input type="file" name="photo" value="<?php echo($result->photo) ;?>">
</td>
</tr>
<tr align="center" valign="top">
<td colspan="2">
<input type="submit" value="modifier">
</td>
</tr>
</table>
</form>
<?php
}//fin if
?>
je trouve pas la raison
qwix
Mar 10 2005, 01:59 PM
elstef
Mar 10 2005, 02:04 PM
je l'ai un peut modifié =), je suis pas un expert, mais je cherche a comprendre, et pour ca niveau pedago sur mediabox c'est vraiment bien merci
qwix
Mar 10 2005, 02:04 PM
Content que ça te serve
Tiens nous au courant pour ton erreur
elstef
Mar 10 2005, 02:08 PM
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
ca doit etre une erreur de syntaxe sql =)
non =)
qwix
Mar 10 2005, 02:14 PM
fait voir un echo $sql; pour voir ce qu'il te donne
elstef
Mar 10 2005, 02:16 PM
comment je fais ca.
elstef
Mar 10 2005, 02:22 PM
SELECT * FROM promotions WHERE id_promotion = 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
voici le message
qwix
Mar 10 2005, 02:47 PM
Le paramètre d'url n'est pas correctement récupéré, vérifie qu'il existe bien
elstef
Mar 10 2005, 03:01 PM
il existe je pense :
while( $result = mysql_fetch_object( $requete ) )
{
echo("<div align=\"center\">".$result->promotion." ".$result->description." <a href=\"modification.php?idpromotion=".$result->id_promotion."\">modifier</a><br>\n") ;
}
voici le tableau sql :
CREATE TABLE promotions (
id_promotion int(11) NOT NULL auto_increment,
type varchar(255) NOT NULL default '',
description longtext NOT NULL default '',
prix int(11) NOT NULL default '',
photo varchar(255) NOT NULL default '',
PRIMARY KEY (id_promotion)
)
qwix
Mar 10 2005, 03:05 PM
Effectivement c'est bizarre, et dans ta source HTML générée on peut voir ce qu'il y a ?
mexandre
Mar 10 2005, 03:15 PM
[quote]SELECT * FROM promotions WHERE id_promotion = 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
voici le message[/quote]
Après id_promotion =, essaye de mettre ton critère avec des apostrophes (') au lieu de guillemets, c'est ce que te dit le message, il n'interprête pas les guillemets dans la requête sql.
elstef
Mar 10 2005, 04:03 PM
voici l'instruction telle qu'elle etait
$sql = "SELECT * FROM promotions WHERE id_promotion = ".$id ;
j'ai essayé le choses suivantes
$sql = 'SELECT * FROM promotions WHERE id_promotion = '.$id ;
$sql = 'SELECT * FROM promotions WHERE id_promotion = .$id' ;
$sql = 'SELECT * FROM promotions WHERE id_promotion =' .'$id' ;
j'ai la même erreur
SELECT * FROM promotions WHERE id_promotion = 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
mexandre
Mar 10 2005, 04:34 PM
$sql = "SELECT * FROM promotions WHERE id_promotion = $id" ;
C'est la bonne synthaxe.
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'informations, la mise en page et les images, veuillez
cliquer ici.