Jump to content

[SOLVED] PHP mysql_query() UPDATE deletes row.


nonexistentera

Recommended Posts

I have no idea how this happens. I have tried the SQL straight through phpMyAdmin and it works perfectly, but yet when I try it through the script, it deletes the row instead of just updating it.

It is set into a function below

 

function Confirm(){
global $HTTP_SERVER_VARS, $user_info;

$id = $_GET["id"];
$md5 = $_GET["secret"];
if (!$id)
	httperr();

$res = mysql_query("SELECT passhash, editsecret, status FROM users WHERE id = $id");
$row = mysql_fetch_array($res);

if (!$row)
	httperr();

if ($row["status"] != "pending") {
	header("Refresh: 0; url=/ok?type=confirmed");
	exit();
}

$sec = hash_pad($row["editsecret"]);
if ($md5 != md5($sec))
	httperr();
$updateSQL = "UPDATE `users` SET `status` = 'confirmed' WHERE `id` =".$id." LIMIT 1 ";
mysql_query($updateSQL) or die(mysql_error());

logincookie($id, $row["passhash"]);

header("Location: /ok?type=confirm");

}

I have tried the $updateSQL and it returns no errors, but the mysql_query is deleting it.

 

Any thoughts on why this would be doing this ???

 

Link to comment
Share on other sites

Your last header() redirect needs an exit; statement after it to prevent the remainder of the code on the page from being executed, which I will guess is a DELETE query.

 

Your existing code is executing the UPDATE query, executing the header() redirect, the confirm() function returns to the code that called it, and the rest of the logic on that page is executed.

Link to comment
Share on other sites

Well thank you for your suggestion. I did exactly as you said, and it still didn't work.

After a few cups of coffee, and some holes in the wall, I finally found the issue.

I have a function that deletes users that have not been confirmed after 24 hours, and this is added into my database connection function.

I had the function in my global call file setting clean as true, which deleted the user once the file was called.

This was my bad XD

Thank you for your help, I have always liked this community

 

Thanks

-nonexistentera

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.