Jump to content

Cannot understand how this insert does not work.


smokehut

Recommended Posts

if (isset($_POST[''.$row['id'].'']) === true) {
	$query = "SELECT did, check FROM admin_flag WHERE did = ? AND check = 1";
		$stmt = $db->prepare($query);
		$stmt->bindValue(1, $row['id']);
		$stmt->execute();
				
	if ($stmt->rowCount() < 1) {
		$query2 = "UPDATE users SET user_flag = user_flag - 1 WHERE username = ?";
		$stmt2 = $db->prepare($query2);
		$stmt2->bindValue(1, $row['user']);
		$stmt2->execute();
					
		if ($stmt2->rowCount() > 0) {
			$query1 = "INSERT INTO admin_flag (did, check) VALUES (?, 1)";
				$stmt1 = $db->prepare($query1);
				$stmt1->bindValue(1, $row['id']);
				$stmt1->execute();
						
			if ($stmt1->rowCount() < 1) {
				echo 'Insert Inactive.';
			}
		} else {
			echo 'Update Flag inactive.';
		}
		//header('Location: view_all_cancels.php');
	} else {
        	echo 'User flag already removed for this trade.';
	}
}

Briefly, In the admin side of things, if a host cancels a trade, the user is flagged. I can then remove a user flag via this button. BUT when I run it, it doesn't check the database correctly for a row count on the first

query, secondly then it doesn't insert the values on the third query. Even though when I am testing it it should get to that else.

 

Any help?

Thanks for your help guys, yet I still cannot figure this out for the life of me.. And it's something I've done plenty of times..

if (isset($_POST[$row['id']]) === true) {
	$query1 = "SELECT did, check FROM admin_flag WHERE did = ? AND check = 1";
	$stmt1 = $db->prepare($query1);
	$stmt1->bindValue(1, $row['id']);
	$stmt1->execute();
			
	printf("rows returned: %d\n", $stmt1->affected_rows);
				
	$fetch = $stmt1->fetch(PDO::FETCH_ASSOC);
				
		if ($fetch['did'] == $row['id']) {
			echo 'Row found '.$row['id'];
		} else {
			echo 'Row not found'.$row['id'].' '.$fetch['did'];
		}
        }
}

Even this, I cannot get to return the row ID, I get the output of, returned rows: 0, Row not found, ROW ID and no fetch id.

 

 

I replaced did with deposit_id, and yet still.. A echo rowcount will = 2, and if rowcount > 0 returns else..

 

Read through kickens post more thouroughly and it turns out "check" was my reversed word, not "did" like I assumed. Thanks guys, this is working now !

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.