Russia Posted December 6, 2009 Share Posted December 6, 2009 I currently have this script: <?php // This is displayed if all the fields are not filled in $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; // Convert to simple variables $email_address = $_POST['email_address']; if (!isset($_POST['email_address'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <span style="float: left;"> Email Address: </span> <span style="float: right;"> <input size="40" class="only" style="border:solid 1px #675f39; padding:4px 2px; font-size:12px;" type="text" name="email_address"> </span> <br><br> <hr> <center> <input id="submit" class="submit-button" type="submit" value="Reset Password" > </center> </form> <?php } elseif (empty($email_address)) { echo $empty_fields_message; } else { require_once("inc/config.php"); $email_address = mysql_real_escape_string($email_address); $status = "OK"; $msg=""; //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); if (!stristr($email_address,"@") OR !stristr($email_address,".")) { $msg="<p>Your email address is not in the correct format.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; $status= "NOTOK"; } if($status=="OK") { $query = "SELECT email, username FROM admin WHERE admin.email = '$email_address'"; $st = mysql_query($query); $recs = mysql_num_rows($st); $row = mysql_fetch_object($st); $em = $row->email_address;// email is stored to a variable if ($recs == 0) { echo "<p>Sorry your address is not there in our database. Please try again.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; exit; } function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); $sql = mysql_query("UPDATE admin SET password='$db_password' WHERE email='$email_address'"); $subject = "Your New Password"; $message = "Hello, you have chosen to reset your password. New Password: $random_password http://www.yoursite.com/login Once logged in you can change your password Thanks! Site admin This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: yoursite.com Webmaster<[email protected]>\n X-Mailer: PHP/" . phpversion()); echo "<p>Your new password has been send! Please check your email!</p>"; } else { echo $msg; } } ?> It works perfectly fine, but when I insert put in a email, that is not in the database it says: Sorry your address is not there in our database. Please try again. When it shows that, it cuts of the footer. Look at the pics: Main form: Error message when not valid email: Code: See how it cuts of the footer? Now when I put in a valid email that is found in the database it shows it perfectly. Picture Also, my code is: This document was successfully checked as HTML 4.01 Transitional! Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/ Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 i don't see a footer anywhere in you code. are you sure you're including it? Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972376 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 Yes I just showed u the php code. Do you also need the whole page code? Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972383 Share on other sites More sharing options...
Daniel0 Posted December 6, 2009 Share Posted December 6, 2009 Also, my code is: This document was successfully checked as HTML 4.01 Transitional! You should use strict instead. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972384 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 So what would I change? Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972385 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 You have an exit; statement on the line of code that outputs your error message, so of course nothing else is output on the page after the error. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972387 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 Yes when I remove the exit; it shows this: Basically it shows that its not the valid and valid at the same time. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972391 Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 you logic is incorrect. you need something along the lines of: <?php if ($recs == 0) { echo "<p>Sorry your address is not there in our database. Please try again.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; } else { makeRandomPassword(); } ?> Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972396 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 So whats the whole correct code? I really do not know what to change? All you did was add an else Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972398 Share on other sites More sharing options...
FaT3oYCG Posted December 6, 2009 Share Posted December 6, 2009 Exactly add the else and move the line that generates a password. It should also read "Your password has been sent! Please check your e-mail.", I wont explain why, it's just how it works. I would also substitute the exclamation mark for a comma maybe as there is no need to shout at your users . Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972400 Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 i was just giving an example of the appropriate logic. otherwise, you're executing both the success and error messages. i know you just want me to rewrite the whole thing for you and perhaps won't even consider what i'm currently saying, but it'd be better that you fully understand such a simple logical issue so as to better serve yourself in the future. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972401 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 @mrMarcus, Okay so I did this: <?php // This is displayed if all the fields are not filled in $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; // Convert to simple variables $email_address = $_POST['email_address']; if (!isset($_POST['email_address'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <span style="float: left;"> Email Address: </span> <span style="float: right;"> <input size="40" class="only" style="border:solid 1px #675f39; padding:4px 2px; font-size:12px;" type="text" name="email_address"> </span> <br><br> <hr> <center> <input id="submit" class="submit-button" type="submit" value="Reset Password" > </center> </form> <?php } elseif (empty($email_address)) { echo $empty_fields_message; } else { require_once("inc/config.php"); $email_address = mysql_real_escape_string($email_address); $status = "OK"; $msg=""; //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); if (!stristr($email_address,"@") OR !stristr($email_address,".")) { $msg="<p>Your email address is not in the correct format.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; $status= "NOTOK"; } if($status=="OK") { $query = "SELECT email, username FROM admin WHERE admin.email = '$email_address'"; $st = mysql_query($query); $recs = mysql_num_rows($st); $row = mysql_fetch_object($st); $em = $row->email_address;// email is stored to a variable if ($recs == 0) { echo "<p>Sorry your address is not there in our database. Please try again.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; } else { function makeRandomPassword() $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; $random_password = makeRandomPassword(); $db_password = md5($random_password); $sql = mysql_query("UPDATE admin SET password='$db_password' WHERE email='$email_address'"); $subject = "Your New Password"; $message = "Hello, you have chosen to reset your password. New Password: $random_password [url=http://www.yoursite.com/login]http://www.yoursite.com/login[/url] Once logged in you can change your password Thanks! Site admin This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: yoursite.com Webmaster<[email][email protected][/email]>\n X-Mailer: PHP/" . phpversion()); echo "<p>Your new password has been send! Please check your email!</p>"; } } } ?> It gives me this error: Parse error: syntax error, unexpected T_VARIABLE, expecting '{' in /home/public_html/accounts-forgot2.php on line 200 I tried to do what you have me. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972403 Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 ok, i'll put it in Layman's terms: <?php if (the user's email address does not exist in the database, display error) //$recs == 0 { echo "<p>Sorry your address is not there in our database. Please try again.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back"; } else { //call the function that is going to create a new random password and email it out; //you don't need to create the function here, you simply need to call it; //BUT, make sure you create the function somewhere in your script, preferably in a file to be included called function.php, or something along those lines makeRandomPassword(); } ?> that's the basic logic. you need to check if the user exists .. if they do, great, if not, execute function to create a random password; Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972408 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 Okay, so with his code, can you combine in with mine? I tried it again but it wouldent work. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972411 Share on other sites More sharing options...
Russia Posted December 6, 2009 Author Share Posted December 6, 2009 Bump. Link to comment https://forums.phpfreaks.com/topic/184177-php-code-cuts-of-footer/#findComment-972422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.