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>'; } ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 Where abouts do i add that Quote Link to comment 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); Quote Link to comment 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()); Quote Link to comment 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 Quote Link to comment 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]) Quote Link to comment 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 Quote Link to comment 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 blank screen appears Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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?? Quote Link to comment Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 none at all Quote Link to comment 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']; Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
porko2004 Posted September 14, 2008 Author Share Posted September 14, 2008 error bjohn-da-silva@hotmail.comcjohn-da-silva@hotmail.comUnknown column 'username' in 'where clause' Quote Link to comment 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. Quote Link to comment 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 bjohn-da-silva@hotmail.comcjohn-da-silva@hotmail.comYou have successfully changed your email.Return to main page this shouldnt appear bjohn-da-silva@hotmail.comcjohn-da-silva@hotmail Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.