jamesxg1 Posted October 12, 2009 Share Posted October 12, 2009 Hiya peeps, I have this. function DropUser($duser_id, $user_email, $user_username) { if(isset($_SESSION['admin_username']) && isset($_SESSION['admin_id']) && isset($_SESSION['admin_session_key'])) { $this->duser_id = mysql_real_escape_string(trim(addslashes(strip_tags(is_numeric($duser_id))))); $this->user_email = mysql_real_escape_string(trim(addslashes(strip_tags($user_email)))); $this->user_username = mysql_real_escape_string(trim(addslashes(strip_tags($user_username)))); if(!empty($this->duser_id) && !empty($this->user_email) && !empty($this->user_username)) { $this->dropusersql = "DELETE FROM `members` WHERE `members`.`user_id` = '$this->duser_id' AND `members`.`username` = '$this->user_username' AND `members`.`emailaddress` = '$this->user_email' LIMIT 1"; $this->run_dropusersql = mysql_query($this->dropusersql) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); $this->removecomplete = '<font color="green"> - The user you select was removed.</font>'; return($this->removecomplete); } else { $this->emptyfields = "<font color='red'> - You have left mandatory fields empty.</font>"; return($this->emptyfields); } } else { header('Location: login.php'); } } (Part of a class). I get the print back (<font color="green"> - The user you select was removed.</font>) but the query isnt deleting the row. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/ Share on other sites More sharing options...
lemmin Posted October 12, 2009 Share Posted October 12, 2009 The problem might be in your query functions that you didn't post. Maybe unrelated, but if your members.user_id is the primary key, you don't really need those other conditions in the WHERE clause. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935629 Share on other sites More sharing options...
jamesxg1 Posted October 12, 2009 Author Share Posted October 12, 2009 I have tried to use this. DELETE FROM `members` WHERE user_id = '$this->duser_id' AND emailaddress = '$this->user_email' AND username = '$this->user_username' And still nothing. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935630 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2009 Share Posted October 12, 2009 Your code isn't actually testing the result of the query before it returns the "The user you select was removed" message and what trigger_error() does is dependent on the error_reporting level and what the display_errors/log_errors settings are. You also don't need to use class variables for everything inside of a function unless you want or need to access those variables outside of the function. Edit: Also, using both addslashes (which does not escape all the special characters that can break a query) and mysql_real_escape_string is double escaping your data and is wasting processing time. Remove the addslashes() function calls. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935632 Share on other sites More sharing options...
jamesxg1 Posted October 12, 2009 Author Share Posted October 12, 2009 With error reports on all i get is the undefined varible errors lol. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935637 Share on other sites More sharing options...
jamesxg1 Posted October 12, 2009 Author Share Posted October 12, 2009 How do i get the problem to show peeps. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935643 Share on other sites More sharing options...
gizmola Posted October 12, 2009 Share Posted October 12, 2009 Ok, so when you do your query you are issuing this: $this->run_dropusersql = mysql_query($this->dropusersql) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); In this case, or trigger_error is never processed, because "or" has a lower operator precedence than the assignment "=" operator. http://us2.php.net/manual/en/language.operators.precedence.php This is not unique by any means to PHP. To get what it appears you want, which is to have the return value considered, you could use the higher precedence "||" operator, however, a clearer way to write this (practically out of the PHP manual) is to put in an if condition: $this->run_dropusersql = mysql_query($this->dropusersql); if (!$this->run_dropusersql) { trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); } else { // Query worked ok. With that said, there is an obvious question about your delete approach: -If the user_id is unique (and it's the primary key of the table) why are you including other criteria? All you should need to delete a user, is the user_id. Link to comment https://forums.phpfreaks.com/topic/177450-my-query-is-being-run-with-no-results/#findComment-935711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.