smokehut Posted May 15, 2013 Share Posted May 15, 2013 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 15, 2013 Share Posted May 15, 2013 check out http://www.php.net/manual/en/mysqli-stmt.affected-rows.php Quote Link to comment Share on other sites More sharing options...
smokehut Posted May 15, 2013 Author Share Posted May 15, 2013 I run that within my insert section after the execute, and it just returns "rows inserterted: 0". Quote Link to comment Share on other sites More sharing options...
Barand Posted May 15, 2013 Share Posted May 15, 2013 Did you use it after the update? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 15, 2013 Share Posted May 15, 2013 FYI. This if (isset($_POST[''.$row['id'].'']) === true) { Should be just this if (isset($_POST[$row['id']]) === true) { No need to concatenate empty string to the variable Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted May 15, 2013 Solution Share Posted May 15, 2013 see also: https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
smokehut Posted May 16, 2013 Author Share Posted May 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 Double check kicken's reply. Reserved words require special treatment for use. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 16, 2013 Share Posted May 16, 2013 see also: https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html ... and some fell on stony ground Quote Link to comment Share on other sites More sharing options...
smokehut Posted May 16, 2013 Author Share Posted May 16, 2013 (edited) 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 ! Edited May 16, 2013 by smokehut Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.