porko2004 Posted September 14, 2008 Share Posted September 14, 2008 i have been working on a change email page in php but i cant get it working correctly can someone please help me. I need it to check MYSQL and look at 5 fields and if all data its correct as on db then email will change can anyone help me. The script it below. <?php $connection=mysql_connect("localhost","root","simles"); $db=mysql_select_db("coproj",$connection); $result = mysql_query("select Email from Accounts where AccountID='$_POST[username]'"); if(!$result) { echo "AccountID does not exist."; echo '<br><br><a href="email.php">Return to password page</a>'; } else if (!$_POST['username'] ) { die('You did not fill the Account ID field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['identification'] ) { die('You did not fill the Identification No field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['answer'] ) { die('You did not fill the Answer field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['question'] ) { die('You did not fill the Secret Question field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['oldemail'] ) { die('You did not fill the Old Email field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['newemail'] ) { die('You did not fill the New Email field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['newemail2'] ) { die('You did not fill the Re-type New Email field <br><br> <a href="email.php">Return to change password page</a>'); } else if (!$_POST['oldemail']!= mysql_result($result, 0)) { echo "email invalid."; echo '<br><br><a href="email.php">Return to email page</a>'; } else if($_POST['newemail']!=$_POST['newemail2']) { echo "Your emails don't match."; echo '<br><br><a href="email.php">Return to change password page</a>'; } else $sql=mysql_query("UPDATE Accounts SET email='$_POST[newemail]' where Identification='$_POST[identification]' AND Answer='$_POST[answer]' AND SecretQuestion='$_POST[question]' AND username='$_POST[username]'"); if($sql) { echo "You have successfully changed your email."; echo '<br><br><a href="index.php">Return to main page</a>'; } ?> Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/ Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 are you getting any errors, what is not working, what is it doing that is isnt supposed to? Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640883 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 Ive tried everything nothing appears when i add data not even a error. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640885 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 Add this to the end of all your queries or die (mysql_error()) and see if there is an error there, also echo your inputs to see if they are filled in. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640893 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 Where abouts do i add that Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640895 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 Also put this at the top of your page error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640896 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 $result = mysql_query("select Email from Accounts where AccountID='$_POST[username]'") or die (mysql_error()); $sql=mysql_query("UPDATE Accounts SET email='$_POST[newemail]' where Identification='$_POST[identification]' AND Answer='$_POST[answer]' AND SecretQuestion='$_POST[question]' AND username='$_POST[username]'") or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640898 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 i get email invalid but it the right email Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640902 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 if (!$_POST['oldemail']!= mysql_result($result, 0)) is this line supposed to be if ($_POST['oldemail'] != $result[0]) Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640904 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 no same error that means the same thing can u fix it for me please Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640905 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 Try this and see what you get I found another thing that i missed. you are not actually fetching the info from the database. <?php error_reporting(E_ALL); $connection=mysql_connect("localhost","root","simles"); $db=mysql_select_db("coproj",$connection); $result = mysql_query("select Email from Accounts where AccountID='$_POST[username]'") or die(mysql_error()); if(!$result) { echo "AccountID does not exist."; echo '<a href="email.php">Return to password page</a>'; } $accemail = mysql_fetch_row($result); else if (!isset($_POST['username'])) { die('You did not fill the Account ID field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['identification'])) { die('You did not fill the Identification No field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['answer'])) { die('You did not fill the Answer field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['question'])) { die('You did not fill the Secret Question field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['oldemail'])) { die('You did not fill the Old Email field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['newemail'])) { die('You did not fill the New Email field <a href="email.php">Return to change password page</a>'); } else if (!isset($_POST['newemail2'])) { die('You did not fill the Re-type New Email field <a href="email.php">Return to change password page</a>'); } else if ($_POST['oldemail'] != $accemail) { echo "email invalid."; echo '<a href="email.php">Return to email page</a>'; } else if($_POST['newemail'] != $_POST['newemail2']) { echo "Your emails don't match."; echo '<a href="email.php">Return to change password page</a>'; } else $sql=mysql_query("UPDATE Accounts SET email='$_POST[newemail]' where Identification='$_POST[identification]' AND Answer='$_POST[answer]' AND SecretQuestion='$_POST[question]' AND username='$_POST[username]'") or die(mysql_error()); if($sql) { echo "You have successfully changed your email."; echo '<a href="index.php">Return to main page</a>'; } ?> Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640911 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 blank screen appears Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640912 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 I updated the code above try it again. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640913 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 same error going to send u a PM with my email Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640916 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 dont understand what u wont me to do cause if i add echo $accemail; i dont have that in form Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640922 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 I added it to the one that I gave to you. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640928 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 yer i saw it but same error Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640929 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 you should be getting more that just the error, are you getting the email twice, once, or not at all?? Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640930 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 none at all Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640932 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 show the code for the page where you are submitting the data from. You should be getting it at least once with echo $_POST['oldemail']; Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640933 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 <div class="style4">Change Email</div> <div class="center_content"> <div class="news_post"> <center><br /> <br /> <table cellspacing="1" cellpadding="5"> <form action="go_to_email2.php" method="POST"> <td class="list" align="right" width="242" height="1">Account ID: </td> <td class="list" width="252" height="1"> <input type="text" name="username" maxlength="30" /> </td> <tr> <td class="list" align="right" width="242" height="1">identification No. : </td> <td class="list" width="252" height="1"> <input type="text" name="identification" maxlength="30" /> </td> </tr> <tr> <td class="list" align="right" width="242" height="1">Secret Question: </td> <td class="list" width="252" height="1"> <input type="text" name="question" maxlength="30" /> </td> </tr> <tr> <td class="list" align="right" width="242" height="1">Answer: </td> <td class="list" width="252" height="1"> <input type="text" name="answer" maxlength="30" /> </td> </tr> <tr> <td class="list" align="right" width="242" height="1">Old Email: </td> <td class="list" width="252" height="1"> <input type="email" name="oldemail" maxlength="30" /> </td> </tr> <tr> <td class="list" align="right" width="242" height="1">New Email: </td> <td class="list" width="252" height="1"> <input type="email" name="newemail" maxlength="30" /> </td> </tr> <tr> <td class="list" align="right" width="242" height="1">Re-type New Email: </td> <td class="list" width="252" height="1"> <input type="text" name="newemail2" maxlength="30" /> </td> </tr> <tr> <td class="listtitle" align="center" colspan="2" height="23"> <label><button type="submit" name="submit" value="Register" >Submit</button></label> </form> </td> </tr> <tr> </tr> </form> </table> <br /> <a href="index.php">Return to main page</a> </center> <p> </p> </div> </div> </div> Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640934 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 that page is fine, this is what I have for the 2nd page, and it works fine on my server <?php error_reporting(E_ALL); $connection=mysql_connect("localhost","root","simles"); $db=mysql_select_db("coproj",$connection); $result = mysql_query("select Email from Accounts where AccountID='$_POST[username]'") or die(mysql_error()); if(!$result) { echo "AccountID does not exist."; echo '<a href="email.php">Return to password page</a>'; } $row = mysql_fetch_row($result); $accemail = $row[0]; echo "b" . $accemail; echo "c" . $_POST['oldemail']; if (!isset($_POST['username'])) { die('You did not fill the Account ID field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['identification'])) { die('You did not fill the Identification No field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['answer'])) { die('You did not fill the Answer field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['question'])) { die('You did not fill the Secret Question field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['oldemail'])) { die('You did not fill the Old Email field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['newemail'])) { die('You did not fill the New Email field <a href="email.php">Return to change password page</a>'); } if (!isset($_POST['newemail2'])) { die('You did not fill the Re-type New Email field <a href="email.php">Return to change password page</a>'); } if ($_POST['oldemail'] != $accemail) { echo "email invalid."; echo '<a href="email.php">Return to email page</a>'; die(); } if($_POST['newemail'] != $_POST['newemail2']) { echo "Your emails don't match."; echo '<a href="email.php">Return to change password page</a>'; die(); } $sql=mysql_query("UPDATE Accounts SET email='$_POST[newemail]' where Identification='$_POST[identification]' AND Answer='$_POST[answer]' AND SecretQuestion='$_POST[question]' AND username='$_POST[username]'") or die(mysql_error()); if($sql) { echo "You have successfully changed your email."; echo '<a href="index.php">Return to main page</a>'; } ?> you can delete the 2 echo lines once you are done with it, I just used them for testing, and it worked. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640939 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 error [email protected]@hotmail.comUnknown column 'username' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640943 Share on other sites More sharing options...
peranha Posted September 14, 2008 Share Posted September 14, 2008 $sql=mysql_query("UPDATE Accounts SET email='$_POST[newemail]' where Identification='$_POST[identification]' AND Answer='$_POST[answer]' AND SecretQuestion='$_POST[question]' AND username='$_POST[username]'") or die(mysql_error()); this where you error is coming from. You dont have a column username in you database. Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640945 Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 ive fixed that error but this appears [email protected]@hotmail.comYou have successfully changed your email.Return to main page this shouldnt appear [email protected]@hotmail Link to comment https://forums.phpfreaks.com/topic/124135-change-email-help-please/#findComment-640947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.