probleme d' update dans mes profils membres
Posté : 26 mai 2009, 13:11
Salut les gens, voila j' ai lu le tuto "forums complet" du sdz et j' ai souhaiter l' utiliser sur mon site et j' ai deux souci.
Le premier, j' ai bien l' avatar qui est uploadé, mais il n' apparait pas dnas la fiche du membre, et n' est pas updaté dans la bdd (surement la le souci).
Le deuxieme, lorsqu' on valide les changements dans le profil, j' ai le bon message "profil modifié", mais y' a quelque chose qui tue ma session, puisque je suis aussitot deconnecté!
Enfin bref bizarre :euh:
voici le code pour modifier le profil mprofil.php:
Voici maintenant la page de traitement mprofil2.php :
Si vous pouviez m' aider sur ce coup, je n' ai rien qui s' update du tout.
Le premier, j' ai bien l' avatar qui est uploadé, mais il n' apparait pas dnas la fiche du membre, et n' est pas updaté dans la bdd (surement la le souci).
Le deuxieme, lorsqu' on valide les changements dans le profil, j' ai le bon message "profil modifié", mais y' a quelque chose qui tue ma session, puisque je suis aussitot deconnecté!
Enfin bref bizarre :euh:
voici le code pour modifier le profil mprofil.php:
<?php
if(isset($_SESSION['pseudo']) && $_SESSION['pseudo'] == $_GET['pseudo'])
{
echo '<table width="180" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/moncompte/mh.gif"> </td></tr><tr><td height="141" valign="top" background="images/moncompte/mm.gif"><table width="170" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Mes infos<br />Mon avatar</td></tr></table></td></tr><tr><td height="20" background="images/moncompte/mb.gif"> </td></tr></table>';
}
else
{
echo '<script type="text/javascript"> google_ad_client = "pub-2988340172457918"; google_ad_slot = "6212945609"; google_ad_width = 160; google_ad_height = 600; </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}
?></td>
<td width="23"> </td>
<td width="697" valign="top"><table width="695" height="180" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="19" background="images/profil/pmh.gif"> </td>
</tr>
<tr>
<td height="139" align="center" valign="top" background="images/profil/pmm.gif"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><?php
mysql_connect("localhost", "bernay", "elodie27");
mysql_select_db("bernay");
?>
<?php
if(isset($_SESSION['pseudo']) && $_SESSION['pseudo'] == $_GET['pseudo'])
{
}
else
{
echo '<SCRIPT LANGUAGE="JavaScript">
document.location.href="halte.php"
</SCRIPT>';
exit;
}
?>
<?
$requete2 = mysql_query('SELECT pseudo, email, site, signature, msn, localisation, avatar FROM connexion WHERE pseudo="'. $_SESSION['pseudo'] .'"');
if ($data2 = mysql_fetch_assoc($requete2))
{
?>
<h1 class="Style6 Style7"><u>Modifier son profil</u></h1>
<p class="Style6 Style7"> </p>
<form method="post" action="mprofil2.php" enctype="multipart/form-data">
<legend><span class="Style4">Votre pseudo </span><span class="Style4"> : <?php echo'<strong>'.stripslashes(htmlspecialchars($data2['pseudo'])).'</strong>'?><br />
</span></legend>
<legend><span class="Style4"><br />
<label for="password">Nouveau mot de Passe :</label>
<input type="password" name="password" id="password" />
<br />
<br />
<label for="confirm">Confirmer le mot de passe :</label>
<input type="password" name="confirm" id="confirm" />
<br />
<br />
</span></legend>
<legend><span class="Style4">
Contacts
<label for="email">Votre adresse E_Mail :</label>
<input type="text" name="email" id="email"
value="<?php echo stripslashes($data2['email']); ?>" />
<br />
<label for="msn"><br />
Votre adresse MSN :</label>
<input type="text" name="msn" id="msn"
value="<?php echo stripslashes($data2['msn']); ?>" />
<br />
<label for="website"><br />
Votre site web :</label>
<p>
<input type="text" name="website" id="website"
value="<?php echo stripslashes($data2['site']); ?>" />
<br />
</p>
<p> </p>
<p class="Style6"><u>Informations supplémentaire </u></p>
<p> </p>
<legend><span class="Style4">
<label for="localisation">Localisation :</label>
<input type="text" name="localisation" id="localisation"
value="<?php echo stripslashes($data2['localisation']); ?>" />
<br />
</span></legend>
<legend><span class="Style4"><br />
<label for="avatar">Changer votre avatar :</label>
<input type="file" name="avatar" id="avatar" />
(Taille max : 10 ko)<br />
<br />
<label>
<input type="checkbox" name="delete" value="Delete" />
Supprimer l avatar</label>
Avatar actuel : <?php echo'
<img src="./images/avatars/'.$data2['avatar'].'"
alt="pas d avatar" />' ?>
<br />
<br />
<label for="signature">Signature :</label>
<textarea cols="40" rows="4" name="signature" id="signature">
<?php echo stripslashes($data2['signature']); ?></textarea>
</span>
</legend>
<p class="Style4">
<input type="submit" value="Modifier son profil" />
</p></form>
<span class="Style4">
<?php
}
else echo'<p>Une erreur s est produite, veuillez réessayer</p>';
?>
Voici maintenant la page de traitement mprofil2.php :
<?php
if(isset($_SESSION['pseudo']) && $_SESSION['pseudo'] == $_GET['pseudo'])
{
echo '<table width="180" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/moncompte/mh.gif"> </td></tr><tr><td height="141" valign="top" background="images/moncompte/mm.gif"><table width="170" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Mes infos<br />Mon avatar</td></tr></table></td></tr><tr><td height="20" background="images/moncompte/mb.gif"> </td></tr></table>';
}
else
{
echo '<script type="text/javascript"> google_ad_client = "pub-2988340172457918"; google_ad_slot = "6212945609"; google_ad_width = 160; google_ad_height = 600; </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}
?></td>
<td width="23"> </td>
<td width="697" valign="top"><table width="695" height="180" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="19" background="images/profil/pmh.gif"> </td>
</tr>
<tr>
<td height="139" align="center" valign="top" background="images/profil/pmm.gif"><table width="100%" height="19" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="19" valign="top"><div align="center">
<?php
//Maintenant, on se connecte à la base de données
mysql_connect("localhost", "****", "***");
mysql_select_db("****");
//Encore est toujours notre belle variable $i :p
$i = 0;
$temps = time();
$signature = mysql_real_escape_string($_POST['signature']);
$email = mysql_real_escape_string($_POST['email']);
$msn = mysql_real_escape_string($_POST['msn']);
$website = mysql_real_escape_string($_POST['site']);
$localisation = mysql_real_escape_string($_POST['localisation']);
$avatar = mysql_real_escape_string($_POST['avatar']);
$pass = md5($_POST['password']);
$confirm = md5($_POST['confirm']);
//Vérification du mdp
if ($pass != $confirm || empty($confirm) || empty($pass))
{
$mdp_erreur = "Votre mot de passe et votre confirmation diffèrent ou sont vides";
$i++;
}
//Vérification de l'adresse email
//Il faut que l'adresse email n'ait jamais été utilisée (sauf si elle n'a pas été modifiée)
if (strtolower($data1['email']) != strtolower($email))
{
$nombremail = mysql_result(mysql_query("SELECT COUNT(*) FROM connexion WHERE email = '".$email."' AND id != '".$_SESSION['id']."'"), 0);
if ($nombremail!= 0)
{
$email_erreur1 = "Votre adresse email est déjà utilisée par un membre";
$i++;
}
//On vérifie la forme maintenant
if (!preg_match("#^[a-z0-9A-Z._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $email) || empty($email))
{
$email_erreur2 = "Votre nouvelle adresse E-Mail n'a pas un format valide";
$i++;
}
}
//Vérification de l'adrese msn
if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $msn) && !empty($msn))
{
$msn_erreur = "Votre nouvelle adresse MSN n'a pas un format valide";
$i++;
}
//Vérification de la signature
if (strlen($signature) > 200)
{
$signature_erreur = "Votre nouvelle signature est trop longue";
$i++;
}
//Vérification de l'avatar
if (!empty($_FILES['avatar']['size']))
{
//On définit les variables :
$maxsize = 125000; //Poid de l'image
$maxwidth = 180; //Largeur de l'image
$maxheight = 180; //Longueur de l'image
//Liste des extensions valides
$extensions_valides = array( 'jpg' , 'jpeg' , 'gif' , 'png', 'bmp' );
if ($_FILES['avatar']['error'] > 0)
{
$avatar_erreur = "Erreur lors du tranfsert de l'avatar : ";
}
if ($_FILES['avatar']['size'] > $maxsize)
{
$i++;
$avatar_erreur1 = "Le fichier est trop gros :
(<strong>".$_FILES['avatar']['size']." Octets</strong>
contre <strong>".$maxsize." Octets</strong>)";
}
$image_sizes = getimagesize($_FILES['avatar']['tmp_name']);
if ($image_sizes[0] > $maxwidth OR $image_sizes[1] > $maxheight)
{
$i++;
$avatar_erreur2 = "Image trop large ou trop longue :
(<strong>".$image_sizes[0]."x".$image_sizes[1]."</strong> contre
<strong>".$maxwidth."x".$maxheight."</strong>)";
}
$extension_upload = strtolower(substr( strrchr($_FILES['avatar']['name'], '.') ,1));
if (!in_array($extension_upload,$extensions_valides) )
{
$i++;
$avatar_erreur3 = "Extension de l'avatar incorrecte";
}
}
?>
<?php
if ($i == 0) // Si $i est vide, il n'y a pas d'erreur
{
if (!empty($_FILES['avatar']['size']))
{
//On déplace l'avatar
$avatar = time();
$nomavatar = str_replace(' ','',$avatar).".".$extension_upload;
$avatar = "./images/avatars/".str_replace(' ','',$avatar).".".$extension_upload;
move_uploaded_file($_FILES['avatar']['tmp_name'],$avatar);
mysql_query('UPDATE connexion
SET avatar = '.$nomavatar.'
WHERE pseudo = '.$_SESSION['pseudo']);
}
//Une nouveauté ici : on peut choisisr de supprimer l'avatar
if (isset($_POST['Delete']))
{
mysql_query('DELETE avatar
FROM connexion WHERE pseudo = '.$_SESSION['pseudo']);
}
echo'<h1>Modification terminée</h1>';
echo'<p>Votre profil a été modifié avec succès !</p>';
//On modifie la table
mysql_query("
UPDATE connexion
SET passe ='".$pass."' , email = '".$email."' ,
msn = '".$msn."' , site = '".$website."',
signature = '".$signature."' ,
localisation = '".$localisation."'
WHERE pseudo = '".intval($_SESSION['pseudo'])."'") or die (mysql_error());
//Et on définit de nouvelles variables de sesssion
//Pour celà on a besoin de la bdd
$requete = mysql_query('SELECT id, rang FROM connexion WHERE pseudo = "'. $_SESSION['pseudo'] .'"');
if ($data = mysql_fetch_assoc($requete))
{
$_SESSION['pseudo'] = $data['pseudo'];
$_SESSION['level'] = $data['rang'];
}
}
else
{
echo'<h1>Modification interrompue</h1>';
echo'<p>Une ou plusieurs erreurs se sont produites pendant la modification du profil</p>';
echo'<p>'.$i.' erreur(s)</p>';
echo'<p>'.$mdp_erreur.'</p>';
echo'<p>'.$email_erreur1.'</p>';
echo'<p>'.$email_erreur2.'</p>';
echo'<p>'.$msn_erreur.'</p>';
echo'<p>'.$signature_erreur.'</p>';
echo'<p>'.$avatar_erreur.'</p>';
echo'<p>'.$avatar_erreur1.'</p>';
echo'<p>'.$avatar_erreur2.'</p>';
echo'<p>'.$avatar_erreur3.'</p>';
echo'<p> Cliquez
<a href="./voirprofil.php?action=modifier">ici</a> pour recommencer</p>';
}
?>
Si vous pouviez m' aider sur ce coup, je n' ai rien qui s' update du tout.