5 Replies - 544 Views - Last Post: 21 March 2011 - 03:42 PM Rate Topic: -----

#1 felito  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 08-December 10

problem in mysqli - check database and email

Posted 21 March 2011 - 10:09 AM

hi guys

I have two functions and they work well, but now i have a problem in the last if

the email is sent like www.yoursite.com/reset_password.php?userid=0&code=

and not http://your.url/set_...5ab72cdcf03ab59

so, the problem is that i can get the value of hash and the userid.
If i do an echo "$hash" in the function code(); it shows the value like 564979&code=54c4a2767c2f485185ab72cdcf03ab59
my question is, how i can do the same in the last if? above two functions. Same occur in the last select select userid from password_reset where code=? none userid is showed, it is always zero.


<?
function check($sql, $db, $email) {
	if(!empty($_POST['email'])) {
			
		$email = $_POST["email"];
		if ($sql = $db->prepare("select email from users where email=?")) {
			$sql->bind_param('s', $email);

			$sql->execute();

			$sql->bind_result($email);

			if ($sql->fetch()) {
				return true;
			}
			else {
				return false;
			}
		}
	}
}



function code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass) {

	if (check($sql, $db, $email)) {
	
		$pwdHasher = new PasswordHash(8, FALSE);

		$hash = $pwdHasher->HashPassword($userExists["email"]);

		$sendPass=$hash;
		($sql = $db->prepare('insert into password_reset (code) values (?)'));
		$sql->bind_param('s', $hash);

		$sql->execute();
		$sql->fetch();
		return true;
	}
}




if (code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass)) {
	($sql = $db->prepare("select userid from password_reset where code=?"));

	$sql->bind_param('s', $hash);
	$sql->execute();
	$sql->bind_result($hash);
	$sql->fetch();
echo $hash;
	$pwrurl = "www.yoursite.com/reset_password.php?userid=" .$hash . "&code=" . $sendPass;

	$mailbody = "Dear user,<br><br>If this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com<br>
			To reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.<br> <a href='$pwrurl'>$pwrurl</a>  <br> <br>
			Thanks,\nThe Administration";

	$mail->MsgHTML($mailbody);

	$mail->AddAddress($email,"Membro");

	$mail->IsHTML(true);

	if(!$mail->Send()) {
		echo "Deu erro: " . $mail->ErrorInfo;
	} else {
		echo "Enviado com sucesso";
	}


	$sql->close();
	$db->close();

}


?>





any help?

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: problem in mysqli - check database and email

#2 calebjonasson  Icon User is offline

  • $bert = new DragonUnicorn(); $bert->rawr();
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: problem in mysqli - check database and email

Posted 21 March 2011 - 10:30 AM

Try naming it something other then hash. If that doesn't work then I would advise that you step through the return to make sure that you are receiving a row properly.
$sql->store_result();
if($sql->num_rows == 1)
{
    //continue your code and check return values.
}


Was This Post Helpful? 0
  • +
  • -

#3 felito  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 08-December 10

Re: problem in mysqli - check database and email

Posted 21 March 2011 - 10:37 AM

View Postcalebj, on 21 March 2011 - 10:30 AM, said:

Try naming it something other then hash. If that doesn't work then I would advise that you step through the return to make sure that you are receiving a row properly.
$sql->store_result();
if($sql->num_rows == 1)
{
    //continue your code and check return values.
}


i already tried to change the name of $hash. In the last if the query doesn't do anything, i can't understand the reason of that. I think the problem is the functions, because before i change to functions i used the exact query in the last if and it works correctly.

So your suggestion it results in an always false condition, if not i can get something different than zero in the userid

Or not?

This post has been edited by felito: 21 March 2011 - 10:39 AM

Was This Post Helpful? 0
  • +
  • -

#4 JaKWaC  Icon User is offline

  • D.I.C Head

Reputation: 76
  • View blog
  • Posts: 234
  • Joined: 15-November 10

Re: problem in mysqli - check database and email

Posted 21 March 2011 - 10:40 AM

You can't pass values back through a functions parameter list. You have to return the value.


There is a way to kind of do what you want but I'd suggest not using it and learning how functions work.


http://php.net/manua...rences.pass.php
Was This Post Helpful? 0
  • +
  • -

#5 felito  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 08-December 10

Re: problem in mysqli - check database and email

Posted 21 March 2011 - 11:05 AM

View PostJaKWaC, on 21 March 2011 - 10:40 AM, said:

You can't pass values back through a functions parameter list. You have to return the value.


There is a way to kind of do what you want but I'd suggest not using it and learning how functions work.


http://php.net/manua...rences.pass.php

can you show me what alterations i must do in the code? to use functions. i change the second function to return $sendPass mas the result is the same, email is sent without values

EDIT: code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass).$sendpass;



50%solved, but the userid continue zero

This post has been edited by felito: 21 March 2011 - 11:12 AM

Was This Post Helpful? -1
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: problem in mysqli - check database and email

Posted 21 March 2011 - 03:42 PM

How about you put in the effort to read the link JaKWaC provided instead of saying "fix my code"?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1