rolly41
Messages postés242Date d'inscriptiondimanche 16 novembre 2008StatutMembreDernière intervention18 septembre 2023
-
5 mars 2013 à 09:15
rolly41
Messages postés242Date d'inscriptiondimanche 16 novembre 2008StatutMembreDernière intervention18 septembre 2023
-
6 mars 2013 à 14:12
Bonjour,
J'ai créé une page nommé "mon-profil.php" qui est utilisée pour modifier les informations de son compte (mail, mdp, ...).
Un formulaire y est présent pour modifier les champs (normal). Mais je ne parvient pas à modifier les valeurs de la table en question.
Voici la totalité de la page :
<?php $title='Mon profil';
include ("head.php");
include("banniere.php"); ?>
<table width="1015px" border="0" align="center">
<tr>
<th class="hleft" width="4"> </th>
<th class="hmiddle"><?php echo $title; ?></th>
<th class="hright" width="4"> </th>
</tr>
<tr>
<td class="page" colspan="3" width="1"><hr /></td>
</tr>
<tr>
<td class="page" colspan="3" align="center">
<?php
?>
<?php
if ($id != '0')
{
$dn = mysql_query('select * from membre where id="'.$id.'"');
if(mysql_num_rows($dn)>0)
{
$dnn = mysql_fetch_array($dn);
$error = FALSE;
$registerOK = FALSE;
if(isset($_POST["modification"]))
{
if(empty($_POST["passwd"]) OR empty($_POST["passwd1"]) OR empty($_POST["mail"]) OR empty($_POST["reponse"]))
{
echo '<font color="#990000"><b>Vous devez obligatoirement remplire les champs suivant :<br />Mail, Mot de passe, Confirmation de mot de passe et Réponse secrète !</b></font>';
}
else
{
if ($_POST['passwd'] != $_POST['passwd1'])
{
echo '<font color="#990000"><b>Les deux mot de passe sont différent !</b></font>';
}
else
{
if(strlen($_POST["passwd"] > 20))
{
echo '<font color="#990000"><b>Votre mot de passe ne doit pas dépasser <strong>20 caractères</strong> !</b></font>';
}
else
{
if(!filter_var($_POST["mail"], FILTER_VALIDATE_EMAIL))
{
echo '<font color="#990000"><b>Votre adresse Mail est incorrecte !</b></font>';
}
else
{
if($_POST['reponse'] != $dnn['r_secret'])
{
echo '<font color="#990000"><b>Votre réponse secrète est incorrecte !</b></font>';
}
else
{
$sql = "UPDATE membre SET passwd='".mysql_real_escape_string($_POST['passwd'])."' , mail='".mysql_real_escape_string($_POST['mail'])."' , presentation='".mysql_real_escape_string($_POST['presentation'])."' , where id=".mysql_real_escape_string($_POST['id']);
$sql = mysql_query($sql);
if($sql)
{
echo '<font color="#009900"><b>Modifications réussie !</b></font>';
}
else
{
echo '<font color="#990000"><b>Erreur dans la requête SQL</b></font>';
}
}
}
}
}
}
}
?>
<form action="mon-profil.php" method="POST">
<table width="63%" name="informations" align="center" border="0">
<tr>
<td valign="bottom" colspan="3" align="center"><font size="+1">Modifiez votre profil</font></td>
</tr>
<tr>
<td valign="top" width="102" align="center"><?php echo html_entity_decode($dnn['pseudo'], ENT_QUOTES, 'UTF-8'); ?><br />
<?php echo '<img src="images/avatars/membres/'.html_entity_decode($dnn['avatar'], ENT_QUOTES, 'UTF-8').'.png" alt="Avatar du membre" style="max-width:100px;max-height:100px;" /><br />'; ?>
<a href="#"><u>Modifier mon avatar</u></a>
</td>
<td class="left" valign="top">
<table>
<tr>
<td><font color="#990000"><b>*</b></font>Changer d'adresse mail</td>
<td><?php echo '<input type="text" name="mail" value="'.html_entity_decode($dnn['mail'], ENT_QUOTES, 'UTF-8').'"/>'; ?></td>
</tr>
<tr>
<td><font color="#990000"><b>*</b></font>Nouveau mot de passe</td>
<td><input type="password" name="passwd" /></td>
</tr>
<tr>
<td><font color="#990000"><b>*</b></font>Confirmez mot de passe</td>
<td><input type="password" name="passwd1" /></td>
</tr>
</table>
</td>
<td valign="top" width="220px" style="border-width:0 0 0 1px; border-style:solid; border-color:#000000;">
Question secrète :<br />
<font color="#000099"><?php echo html_entity_decode($dnn['q_secret'], ENT_QUOTES, 'UTF-8'); ?></font><br />
<font color="#990000"><b>*</b></font>Réponse secrète :<br />
<input name="reponse" type="text" />
</td>
</tr>
<tr>
<td colspan="3" style="border-width:1px 0 0 0; border-style:solid; border-color:#000000;" align="center">
<h3>Présentation :</h3>
</td>
</tr>
<tr>
<td class="left" valign="top" colspan="3" align="center">
<pre><textarea name="presentation"><?php echo html_entity_decode($dnn['presentation'], ENT_QUOTES, 'UTF-8'); ?></textarea></pre>
</td>
</tr>
<tr>
<td colspan="3" style="border-width:1px 0 0 0; border-style:solid; border-color:#000000;" align="center">
<h3>Personnage Lié</h3>
</td>
</tr>
<tr>
<td colspan="3" valign="top">
<table width="87%" align="center" border="1">
<tr>
<td align="center" valign="top">Pseudo</td>
<td align="center" valign="top">Classe</td>
<td align="center" valign="top" width="50">Niveau</td>
<td align="center" valign="top">Serveur</td>
</tr>
<?php
$sql = 'select id_personnage, id_membre, classe, pseudo, serveur, niveau from personnage where id_membre="'.$id.'"';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($data = mysql_fetch_assoc($req))
{
echo '<tr><td align="center" valign="top"><a href="personnage.php?id='.html_entity_decode($data['id_personnage'], ENT_QUOTES, 'UTF-8').'" style="text-decoration:none;color:#000099;"><u>'.html_entity_decode($data['pseudo'], ENT_QUOTES, 'UTF-8').'</u></a></td><td align="center" valign="top"><font color="000099">'.html_entity_decode($data['classe'], ENT_QUOTES, 'UTF-8').'</font></td><td align="center" valign="top">'.html_entity_decode($data['niveau'], ENT_QUOTES, 'UTF-8').'</td><td align="center" valign="top">'.html_entity_decode($data['serveur'],ENT_QUOTE, 'UTF-8').'</td></tr>';
}
?>
<?php
$sql = 'select COUNT(*) from personnage WHERE id_membre="'.$id.'"';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$data = mysql_fetch_array($req);
if ($data[0] == '0')
{
echo '<tr><td colspan="4" align="center" valign="top" style="background-color:#ff0000;"><font color="#ffffff">Vous n\'avez pas de personnage lié</font></td></tr>';
}
?>
<tr><td colspan="4" align="center" valign="top" style="background-color:#009900;"><a href="#"><font color="#000000"><b>Créer un nouveau personnage</b></font></a></td></tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input name="id" value="<?php echo html_entity_decode($dnn['id'], ENT_QUOTES, 'UTF-8'); ?>" type="HIDDEN" />
<input name="modification" value="Enregistrer les modifications" type="submit">
</td>
</tr>
</table>
</form>
<?php
}
else
{ echo 'Utilisateur inconu !';
}
}
else
{ echo 'Vous devez vous connecter pour afficher cette page !<br /><a href="connexion.php">Connexion</a> - <a href="inscription">Inscription</a>';
}
?>
</td>
</tr>
</table>
<?php include("copyright.php"); ?>
Problème rencontré : Quand je clique sur "Enregistrer les modifications", je suis bien redirigé vers la page en question (mon-profil.php), mais j'ai ceci qui s'affiche : "Erreur dans la requête SQL"
Ce message s'affiche suite à ce code :
else
{
$sql = "UPDATE membre SET passwd='".mysql_real_escape_string($_POST['passwd'])."' , mail='".mysql_real_escape_string($_POST['mail'])."' , presentation='".mysql_real_escape_string($_POST['presentation'])."' , where id=".mysql_real_escape_string($_POST['id']);
$sql = mysql_query($sql);
if($sql)
{
echo '<font color="#009900"><b>Modifications réussie !</b></font>';
}
else
{
echo '<font color="#990000"><b>Erreur dans la requête SQL</b></font>';
}
}
Ce code mysql (update) est utilisé pour modifier les valeurs enregistré dans la base de données (je suis bien connecté à la base de donnée). Et je souhaite modifier les informations d'un membre au quel sont id de membre (auto incrémenté et donc unique) est $id
Je ne trouve pas la source du problème, pourriez-vous me guider ?
P.S : Ce n'est pas un problème de connexion entre le serveur et la base de données. Je sais lire les informations de la table, mais pas les modifier.
Informations complémentaire : Base de données : En MYSQL et pas en MSQLI
Table : UTF-8 Unicode (utf8) Testé sur : localhost et pas testé sur le serveur chez mon hébergeur
La base de données en localhost est la même que sur mon serveur
Informations phpmyadmin localhost :
Apache/2.2.21 (Win32) PHP/5.3.10
Version du client MySQL : mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $
Extension PHP: mysqli
Version: 3.4.10.1, dernière version stable : 3.5.7 Informations phpmyadmin serveur :
Apache/2.4.3
Version du client de base de données: libmysql - 5.5.28
Extension PHP: mysqli
Version: 3.5.7 (à jour)
A voir également:
Impossible de modifier valeur d'une base de données.
6 mars 2013 à 14:12
La virgule était bien la cause du problème :D
Merci ;)