Jump to content

[SOLVED] Can someone take a kook at this and tell me what I am missing


affordit

Recommended Posts

<?php

include("sharons_dbinfo.inc.php");

mysql_connect(mysql,$username,$password);

mysql_select_db($database) or die( "Unable to select database");

 

$query = "select * from login WHERE email='$email' and lost_password_answer='$lost_password_answer'";

$result=mysql_query($query) or die (mysql_error());

$num=mysql_numrows($result);

mysql_close();

 

 

$i=0;

while ($i < $num) {

$name=mysql_result($result,$i,"name");

$psword=mysql_result($result,$i,"psword");

$email=mysql_result($result,$i,"email");

$lost_password_answer=mysql_result($result,$i,"lost_password_answer");

$valid=mysql_result($result,$i,"valid");

 

// MAIL THE PASSWORD

 

$to = "$email";

$subject = "Your Password";

$message="You recently requested your password be mailed to you\n Thank you for using our service your password is $psword";

$headers = "From: [email protected]";

$sent = mail($to, $subject, $message, $headers) ;

if($sent)

{print "Your password has been sent to $email and it is $psword<br><br><a href='index.php'>Back to main page</a>"; }

else

{print "We encountered an error sending your mail"; }

++$i;

}

?>

Try something like.

<?php

include("sharons_dbinfo.inc.php");
mysql_connect(mysql, $username, $password);
mysql_select_db($database) or die("Unable to select database");

$query = "SELECT * FROM `login` WHERE `email` = '$email' and `lost_password_answer` = '$lost_password_answer'";
$result = mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result); 
$array = mysql_fetch_array($result);

mysql_close();

if($num == 1)
{
   while ($i < $num)
   {
       $name = $array['name'];
       $psword = $array['psword'];
       $email = $array['email'];
       $lost_password_answer = $array['lost_password_answer'];
       $valid = $array['valid'];

       // MAIL THE PASSWORD
       $to = "$email"; 
       $subject = "Your Password"; 
       $message="You recently requested your password be mailed to you\n Thank you for using our service your password is $psword";
       $headers = "From: [email protected]"; 
       $sent = mail($to, $subject, $message, $headers) ;

           if($sent) 
           {
               print "Your password has been sent to $email and it is $psword<br />
                       <a href=\"index.php\">Back to main page</a>"; 
           } else 
           {
               print "We encountered an error sending your mail";
           }
       $i++;
   }
} else
{
   print "The values you enterd were false";
} 
?>

 

No that doesn't work it comes back with data entered false.

Thanks

 

Well, that means your query is returning no rows. Where are you getting the variables $email and $lost_password_answer from? I don't see them defined before you use them in your query.

They come from this form

 

<?php

include("sharons_dbinfo.inc.php");

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

//

// CHANGE QUERY TO GRAB THE ID

//

$query = "select * from test WHERE email='$email'";

$result=mysql_query($query) or die (mysql_error());

$num=mysql_numrows($result);

 

mysql_close();

 

$i=0;

while ($i < $num) {

$company=mysql_result($result,$i,"company");

$name=mysql_result($result,$i,"name");

$address=mysql_result($result,$i,"address");

$city=mysql_result($result,$i,"city");

$state=mysql_result($result,$i,"state");

$zip=mysql_result($result,$i,"zip");

$phone=mysql_result($result,$i,"phone");

$acct_num=mysql_result($result,$i,"acct_num");

$email=mysql_result($result,$i,"email");

$start_date=mysql_result($result,$i,"start_date");

$end_date=mysql_result($result,$i,"end_date");

$remind_date=mysql_result($result,$i,"remind");

$lost_password=mysql_result($result,$i,"lost_password");

$lost_password_answer=mysql_result($result,$i,"lost_password_answer");

 

echo "$lost_password<br>";

echo "<form action=send_password.php method='POST'><table>";

echo "

<tr>

<td><img src='b_tipp.png' alt='Write your answer to the above question.'>Question:</td><td>$lost_password:</td>

</tr>

<tr>

<td><img src='b_tipp.png' alt='Write your answer to the above question.'>Your Answer:</td><td><input type=text name=lost_password_answer size=30 maxlength=100></td>

</tr>";

echo "<br><tr>

<td align='center' colspan='2'><br><input type=submit name='Submit' value='Send Now'></td>

</tr>

</table>

</form>";

++$i;

}

?>

Are you sure your entering an email and lost password answer that exists in the database?

 

If you are positive that you are, then echo your query out to make sure the variables are set right.

 

<?php

$query = "SELECT * FROM `login` WHERE `email` = '$email' and `lost_password_answer` = '$lost_password_answer'";
$result = mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result); 

echo "<p>$query<p>";

mysql_connect(mysql,$username,$password);

 

wouldn't that need to be

 

mysql_connect([color=red][font=Verdana]$mysql[/font][/color],$username,$password);

 

to match what ever your mysql value would be (unless this is your host name)?

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.