Jump to content

Php code cuts of footer


Russia

Recommended Posts

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:

1_forgot.jpg

 

Error message when not valid email:

2_forgot.jpg

 

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

3_forgot.jpg

 

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

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(); }
?>

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 :).

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.

@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.

 

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.