2016-11-20 5 views
1

So habe ich ein Problem mit meiner MySQL-Abfrage. Wenn ich versuche, die "E-Mail" -Spalte zu ändern, durchläuft es alle if-Anweisungen und zeigt nur, dass ich meine E-Mail erfolgreich geändert habe, aber aus bestimmten Gründen nicht. Bitte sagen Sie mir, wo der Fehler ist ... wahrscheinlich ist es etwas albern, aber ich kann es aus irgendeinem Grund nicht finden.Kann meine MySQL-Datenbank nicht aktualisieren

hier ist die Codierung:

<?php 
 
session_start(); 
 
include 'connection/db_connect.php'; 
 
$sessionname = $_SESSION['name']; 
 
$sql = "SELECT * FROM registered WHERE userName='$sessionname'"; 
 
$result = mysqli_query($conn, $sql); 
 
$currentprofile = "Your profile"; 
 
$selectedprofile = "<h1>Your profile</h1>"; 
 
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){ 
 
\t $username = $row['userName']; 
 
\t $password = $row['password']; 
 
\t $email = $row['email']; 
 
\t $sessionid = $row['id']; 
 
} 
 
$erroremail = null; 
 
$changeEmail = $_POST['changeEmail']; 
 
$changeEmailValue = $_POST['changeEmailValue']; 
 
$changePassword = $_POST['changePassword']; 
 
$changePasswordNew = $_POST['changePasswordNew']; 
 
$changePasswordRepeat = $_POST['changePasswordRepeat']; 
 

 
if(isset($changeEmail)){ 
 
\t if(!empty($changeEmailValue)){ 
 
\t \t $sqlemail = "SELECT email FROM registered where email='$changeEmailValue'"; 
 
\t \t $resultemail = mysqli_query($conn, $sqlemail); 
 
\t \t if(mysqli_num_rows($resultemail) >= 1){ 
 
\t \t \t $erroremail = "<p style='color:red;'>This email is already in use by another user!</p>"; 
 
\t \t } else { 
 
\t \t \t $sqlemailtwo = "UPDATE registered SET email='$changeEmailValue' WHERE id='$sessionid'"; 
 
\t \t \t mysql_query($conn, $sqlemailtwo); 
 
\t \t \t $erroremail = "<p style='color:green;'>You updated ypur email successfully!</p>"; 
 
\t \t } 
 
\t } else { 
 
\t \t $erroremail = "<p style='color:red;'>You didn't enter email!</p>"; 
 
\t } 
 
} 
 

 
if($sessionname == null){ 
 
\t header ('Location: index.php'); // proverka za login 
 
} 
 
?> 
 
<html> 
 
<head> 
 
\t <title><?php echo $currentprofile; ?></title> 
 
\t <style> 
 
\t </style> 
 
</head> 
 
<body> 
 
<div> 
 
<?php echo "Hello, ".$username; ?> | <a href='logout.php'>Logout</a> 
 
<div style='width: 230px; height: 100%;'> 
 

 
<span><?php echo $selectedprofile; ?></span> 
 
<br> 
 
\t Email: 
 
\t <?php echo $erroremail; ?> 
 
\t <form method='post' action='?=changeEmail'> 
 
\t \t <input type='email' name='changeEmailValue' value='<?php echo $email; ?>'> 
 
\t \t <input type='submit' name='changeEmail' value='Change'> 
 
\t </form> 
 
<hr> 
 
\t Password: 
 
\t <form method='post' action='?=changePassword'> 
 
\t \t <input type='password' name='changePasswordCurrent' value='' placeholder='Your current password'> 
 
\t \t <input type='password' name='changePasswordNew' value='' placeholder='New password'> 
 
\t \t <input type='password' name='changePasswordRepeat' value='' placeholder='Repeat new password'> 
 
\t \t <input type='submit' name='changePassword' value='Change'> 
 
\t </form><br> 
 
<hr> 
 
\t Your IP adress: 
 
\t <?php ?> 
 
</div> 
 

 
</body> 
 
</html>

Antwort

0

Ich denke, es ist eine Frage der 'i' ist. Sie können ändern

mysql_query($conn, $sqlemailtwo); to mysqli_query($conn, $sqlemailtwo); 
+1

Nicht nur das, aber 'MYSQL_ASSOC' auch. –

Verwandte Themen