PHP change email address on account when logged in -
i trying enable user change password on account when logged in. however, cant seem work.
do have suggestions?
<?php if ($_post['submitemail']) { $newemail = $_post['email']; $newemail = stripslashes($newemail); $newemail = str_replace("'", "'", "$newemail"); //checks database see if email user types in exists $query = "select * users email = '$newemail'"; $result = mysqli_query($db_connection, $query); $nums = mysqli_num_rows($result); if ($nums >= 1) { //if email exists, inform user echo "email exists"; echo "<br/>click <a href = 'account.php?page=email'> here</a> try again"; } else { //if email not exist, update users email $querychange = "update users set email = '$newemail' id = '$userid'"; $result3 = mysqli_query($db_connection, $querychange); echo "your email has been changed"; } } else { echo "<strong> current email: </strong>$email "; ?> <!-- allows users enter new email address --> <form name="changeemail" id="changeemail" method="post" action="account.php?page=email"> <input type="hidden" value="email" name="account_submit_type"/> <input type='hidden' name='changeemail' value='yes'> <strong> email </strong><input type = "text" name = "email" size="40" value=""> <br> <input type ="button" value="submitemail" onclick="verifyform()"/> </form> <?php } ?>
<input type ="button" value="submitemail" onclick="verifyform()"/>
this has
<input type="submit" value="submitemail"/>
another error: undefined $email:
echo "<strong> current email: </strong>"; echo $email;
has this:
echo "<strong> current email: </strong>"; echo $_post['email'];
full version works me:
<?php if ($_post['submitemail']) { $newemail = $_post['email']; $newemail = stripslashes($newemail); $newemail = str_replace("'", "'", "$newemail"); //checks database see if email user types in exists $query = "select * users email = '$newemail'"; $result = mysqli_query($db_connection, $query); $nums = mysqli_num_rows($result); if ($nums >= 1) { //if email exists, inform user echo "email exists"; echo "<br/>click <a href = 'account.php?page=email'> here</a> try again"; } else { //if email not exist, update users email $querychange = "update users set email = '$newemail' id = '$userid'"; $result3 = mysqli_query($db_connection, $querychange); echo "your email has been changed"; } } else { echo "<strong> current email: </strong>"; echo $_post['email']; ?> <!-- allows users enter new email address --> <form name="changeemail" id="changeemail" method="post" action="#?page=email"> <input type="hidden" value="email" name="account_submit_type"/> <input type='hidden' name='changeemail' value='yes'> <strong> email </strong><input type = "text" name = "email" size="40" value=""> <br> <input type="submit" value="submitemail"/> </form> <?php } ?>
Comments
Post a Comment