Salve, sto faccendo il profilo degli utenti , ma mi servirebbe come fare ad controllare
quando provono ad modificare l'email e io devo verificare se quell'email esiste già.
Ho provato tutti i modi ma non mi riesce.
Ora vi posto il codice che uso:
Codice PHP:
<?php
session_start();
require_once(dirname(__FILE__) . '/../include.php');
require_once(dirname(__FILE__) . '/header.php');
checkLogin('1');
$query = mysql_query ( "SELECT * FROM `users` WHERE `ID` = '" . mysql_real_escape_string ( $_SESSION['user_id'] ) . "'" );
$r= mysql_fetch_assoc ( $query );
if(isset($_POST)) {
$email = mysql_codifica($_POST['email']);
$user = mysql_codifica($_SESSION["user_id"]);
$query = "SELECT * FROM users " .
"WHERE Username = '$user' " .
"OR Email = '$email' ";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) != 0)
{
while ($row = mysql_fetch_array($result))
{
//email già presente nel db QUI DEVE STARE IL CONTROLLO.
if (!$row["Email"] == $email)
{
echo "
";
echo "La casella E-mail, [b]" . $row['Email'] . "[/b] è già presente nel Data Base, scegliere una diversa";
echo "</p>";
}
}
}//Se invece username e email non sono presenti nel db procediamo con l'inserimanto
else
{
$update = "UPDATE `users` SET `Email` = '" . mysql_real_escape_string ( $_POST['email'] ) . "'";
/* if we have a new password via POST we update the old one */
$update .= " WHERE `ID` = " . mysql_real_escape_string ( $_SESSION['user_id'] ) . "";
if ( mysql_query ( $update ) )
{
$msg = 'Your profile was successfully updated!';
}
else {
$error = 'I was unable to save your profile. Please contact the administrator'.mysql_error();
}
}
}
?>
<?php if ( isset ( $error ) ) { echo ' <p class="error">' . $error . '</p>' . "\n"; } ?>
<?php if ( isset ( $msg ) ) { echo ' <p class="msg">' . $msg . '</p>' . "\n"; } ?>
<form class="form" action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="_submit_check" value="1"/>
<table align="center" width="99%">
<tr>
<td><div align="left">Username</div></td>
</tr>
<tr>
<td><div align="left"><input disabled class="input" type="text" name="username" id="username" size="25" maxlength="40" value="<?php echo $r['Username']?>" /></div></td>
</tr>
<tr>
<td><div align="left">Password</div></td>
</tr>
<tr>
<td><div align="left"><input class="input" type="password" name="password" id="password" size="25" maxlength="32" /></div></td>
</tr>
<tr>
<td><div align="left">Email</div></td>
</tr>
<tr>
<td><div align="left"><input class="input" type="text" name="email" id="email" size="25" value="<?php if ( isset ( $_POST['email'] ) ) { echo $_POST['email']; } else { echo $r['Email']; } ?>" /></div></td>
</tr>
<tr>
<td>
<input type="submit" name="Update" value="Update" class="submit-btn" src="images/btn.gif" alt="submit" title="submit" />
<br class="clear" />
</td>
</tr>
</table>
</form>
[url="logout.php"]logout[/url]
<?php require_once(dirname(__FILE__) . '/footer.php');
ed un giorno che ci sto dentro..
in pratica,
se metto pippo@gmail.com l'email utente pippo. deve uscire modifica ok.
invece se metto pluto@gmail.com "ma un utente c'è la già", allora mi deve fare il messaggio
email esiste già.
Mi dite come farE?.
grazie.