Jump to content

[SOLVED] query problem


soycharliente

Recommended Posts

This section isn't working.

I don't really know what information you might need so please feel free to ask for anything that might help clear it up.

 

<?php
$query = "UPDATE blog_users SET password='$new_pw' WHERE MD5(CONCAT('$email', '$lastlogin', 'XXX'))='$rid'";
?>

 

$rid is a hidden field pulled from a $_GET. It's on a password reset form. It's an md5 hash.

 

The form:

<form action="resetPassword.php" method="post">
<input type="hidden" name="rid" value="<?php echo $_GET["rid"]; ?>" />
<p>
	New Password:<br />
	<input type="text" name="new_pw" value="<?php echo $new_pw; ?>" maxlength="255" /><br />
	<?php
	echo ($error_new_pw)?"<span class=\"red\">Enter a valid password. Read the guidelines below.</span><br />":"";
	?>
	<span class="gray smaller">Password should be between 5 and 16 characters long and
	consist of only letters and numbers.</span>
</p>
<p>
	<input type="submit" name="submit_resetPassword" value="Reset Password" /> -
	<input type="reset" name="reset_resetPassword" value="Clear" />
</p>
</form>

 

Processing:

<?php
if (isset($_POST["submit_resetPassword"])) {
if (isset($_POST)) {
	foreach ($_POST as $key => $val) {
		$_POST[$key] = myEscape($val);
	}
}
$new_pw = $_POST["new_pw"];
$rid = $_POST["rid"];
$error_new_pw = (preg_match("/^[a-zA-Z0-9]{5,16}$/", $new_pw)) ? FALSE : TRUE;
$resetPass = FALSE;
if (!$error_new_pw) {
	dbconnect();
	$query = "UPDATE blog_users SET password='$new_pw' WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query);
	$resetPass = TRUE;
	$query = "SELECT * FROM blog_users WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query) or DIE("Error: RESET PASSWORD LOGIN. Contact Webmaster.);
	if (mysql_num_rows($result) > 0) {
		$r = mysql_fetch_assoc($result);
		$user = $r["username"];
		$pass = $r["password"];
		if ($un == $user && $pw == $pass) {
			$_SESSION["user"] = $un;
			$loggedin = TRUE;
			$loginError = FALSE;
			updateLastLogin(getUserId($_SESSION["user"]));
			header("Location: index.php");
			exit;
		}
	}
}
}
?>

Link to comment
Share on other sites

you can use mysql_affected_rows() to find out how many rows are affected by INSERT, REPLACE, UPDATE and DELETE queries.  might come in handy for figuring out whether something is being updated or not.

 

since it seems it isn't, i'm going to guess the culprit is your WHERE clause.  if there are no errors, it means it's a var issue and not a syntax issue.  you say you're passing $rid by GET, but you're assigning it via $_POST.  could that be the issue?

Link to comment
Share on other sites

Got this error:

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /resetPassword.php on line 75

 

That's this line:

<?php
$query = "UPDATE blog_users SET password='$new_pw' WHERE MD5(CONCAT('$email', '$lastlogin', 'XXXXXX'))='$rid'";
?>

Link to comment
Share on other sites

it's always helpful to echo your stuff before running it to see exactly what's going on:

 

		echo 'email: '.$email.', lastlogin: '.$lastlogin.', RID: '.$rid;
	$query = "UPDATE blog_users SET password='$new_pw' WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query);
	$resetPass = TRUE;
	$query = "SELECT * FROM blog_users WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query) or DIE("Error: RESET PASSWORD LOGIN. Contact Webmaster.");

 

you were also missing an ending quote on the DIE() statement after the select.  msqyl_affected_rows() is like mysql_insert_id() - you don't feed it anything (or if you do, you feed it the connection resource, but not the query resource).

Link to comment
Share on other sites

it's always helpful to echo your stuff before running it to see exactly what's going on:

 

		echo 'email: '.$email.', lastlogin: '.$lastlogin.', RID: '.$rid;
	$query = "UPDATE blog_users SET password='$new_pw' WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query);
	$resetPass = TRUE;
	$query = "SELECT * FROM blog_users WHERE MD5(CONCAT('$email', '$lastlogin', 'rbx4life'))='$rid'";
	$result = mysql_query($query) or DIE("Error: RESET PASSWORD LOGIN. Contact Webmaster.");

 

you were also missing an ending quote on the DIE() statement after the select.  msqyl_affected_rows() is like mysql_insert_id() - you don't feed it anything (or if you do, you feed it the connection resource, but not the query resource).

 

I saw that quote error. The page didn't even load when that wasn't there. Don't know how that version of my code made it into my post.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.