seany123 Posted December 4, 2009 Share Posted December 4, 2009 does anyone see anything wrong with these queries? <?php if ($player->gang_id >= 1){ $log_query = $db->execute("INSERT `attack_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } if ($enemy->gang_id >= 1){ $log_query2 = $db->execute("INSERT `defense_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/ Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 your missing the keyword INTO INSERT INTO `attack_log` .... Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971362 Share on other sites More sharing options...
seany123 Posted December 4, 2009 Author Share Posted December 4, 2009 your missing the keyword INTO INSERT INTO `attack_log` .... that hasnt fixed it... i didnt even realise that the INTO keyword was actually needed Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971367 Share on other sites More sharing options...
mrMarcus Posted December 4, 2009 Share Posted December 4, 2009 your missing the keyword INTO INSERT INTO `attack_log` .... that hasnt fixed it... i didnt even realise that the INTO keyword was actually needed it's actually not needed. silly, but true. i see you on this board from time-to-time, and yet, you still post a question like so, "does anyone see anything wrong with these queries?" .. surely you've figured that this will not get you the assistance you would like, right? for all i know it's a trick question. so, i'm going ask you: "do YOU see anything wrong with these queries?" please post what the problem(s) is/are you are having with the query. Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971377 Share on other sites More sharing options...
JAY6390 Posted December 4, 2009 Share Posted December 4, 2009 Is there any way you can debug what the queries being sent are? Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971379 Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 your missing the keyword INTO INSERT INTO `attack_log` .... that hasnt fixed it... i didnt even realise that the INTO keyword was actually needed it's actually not needed. silly, but true. are you sure? what version of Mysql are we talking? I was under the impression that it was, and from my experience with insert queries, it always has been. I don't have a test environment to test in, and google has been no help, so i guess I will have to take your word for it. As for OP, have you tried to second Insert syntax (IE the INSERT INTO (col, col, col,) VALUES(value, value, value)) depending on your version, you may have to use the second syntax. also try echoing the queries to see what they look like, and if they look like what you expect Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971382 Share on other sites More sharing options...
seany123 Posted December 4, 2009 Author Share Posted December 4, 2009 Okay well no i dont see anything wrong with my queries... i have put echos after each query to see if the ifs are working... and they displayed... no errors display when running the queries... the only error is that the query doesnt do what i have told it to. Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971387 Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 What is the query actually doing, and what do you expect it to do Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971393 Share on other sites More sharing options...
seany123 Posted December 4, 2009 Author Share Posted December 4, 2009 What is the query actually doing, and what do you expect it to do well its supposed to insert into my table attack_log or defense_log... and set the values this is the table -- -- Table structure for table `attack_log` -- CREATE TABLE IF NOT EXISTS `attack_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `attack_id` int(11) NOT NULL, `defense_id` int(11) NOT NULL, `attack_gid` int(11) NOT NULL, `defense_gid` int(11) NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `winner_id` int(11) NOT NULL, `exp_gain` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ; i know the connection to the database is fine because im echoing information from the database etc. Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971399 Share on other sites More sharing options...
mrMarcus Posted December 4, 2009 Share Posted December 4, 2009 your missing the keyword INTO INSERT INTO `attack_log` .... that hasnt fixed it... i didnt even realise that the INTO keyword was actually needed it's actually not needed. silly, but true. are you sure? what version of Mysql are we talking? I was under the impression that it was, and from my experience with insert queries, it always has been. I don't have a test environment to test in, and google has been no help, so i guess I will have to take your word for it. As for OP, have you tried to second Insert syntax (IE the INSERT INTO (col, col, col,) VALUES(value, value, value)) depending on your version, you may have to use the second syntax. also try echoing the queries to see what they look like, and if they look like what you expect i wouldn't have thought it myself, but i ran this query without fail: $sql = " INSERT `table` SET `user_id` = 1 "; and it inserted the value '1' into field `user_id` in table `table` .. not at all how i have ever run my INSERT queries. i'm running on MySQL Server version: 5.1.32 / Client version: 5.0.51a (mysqli); i personally was under the impression that you couldn't use SET as part of the INSERT syntax .. don't know what put me under that impression, and never bothered to look it up. Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971435 Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 Hmm, very interesting. The MySQL manual doesn't provide any documentation on that as I could find. Maybe Ill try that out when I get home. I have 5.2.something on my home computer so it might be different. and SET is the old INSERT syntax I believe. I remember using that a while ago, and it suddenly not working. (it worked when using the (column) VALUES() syntax) but according to the manual, both syntaxes are valid. Perhaps the insert into thing has something to do with strict mode being on or off. I'll look that up and see Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971442 Share on other sites More sharing options...
mrMarcus Posted December 4, 2009 Share Posted December 4, 2009 are either $player->gang_id or $gang->gang_id greater than or equal to 1? are you sure? Hmm, very interesting. The MySQL manual doesn't provide any documentation on that as I could find. Maybe Ill try that out when I get home. I have 5.2.something on my home computer so it might be different. and SET is the old INSERT syntax I believe. I remember using that a while ago, and it suddenly not working. (it worked when using the (column) VALUES() syntax) but according to the manual, both syntaxes are valid. Perhaps the insert into thing has something to do with strict mode being on or off. I'll look that up and see true enough. i'm not 100% on my overall SQL configuration on my localhost, so i'm not sure as to what extensions/values, etc., i might have turned on or off. gonna look into a little further though. Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971451 Share on other sites More sharing options...
mrMarcus Posted December 4, 2009 Share Posted December 4, 2009 does anyone see anything wrong with these queries? <?php if ($player->gang_id >= 1){ $log_query = $db->execute("INSERT `attack_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } if ($enemy->gang_id >= 1){ $log_query2 = $db->execute("INSERT `defense_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } i'm guessing the parameters aren't binding properly. are you using PDO (prepared statements)? Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971453 Share on other sites More sharing options...
seany123 Posted December 4, 2009 Author Share Posted December 4, 2009 does anyone see anything wrong with these queries? <?php if ($player->gang_id >= 1){ $log_query = $db->execute("INSERT `attack_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } if ($enemy->gang_id >= 1){ $log_query2 = $db->execute("INSERT `defense_log` SET `attack_id`=?, `defense_id`=?, `attack_gid`=?, `defense_gid`=?, `winner_id`=?, `expgain`=?", array($player->id, $enemy->id, $player->gang_id, $enemy->gang_id, $enemy->id, $g_exploss)); } i'm guessing the parameters aren't binding properly. are you using PDO (prepared statements)? no all the values in the array are all values from another table in my database... and ive echo'd them all to make sure they are okay.. and they are. are either $player->gang_id or $gang->gang_id greater than or equal to 1? are you sure? Hmm, very interesting. The MySQL manual doesn't provide any documentation on that as I could find. Maybe Ill try that out when I get home. I have 5.2.something on my home computer so it might be different. and SET is the old INSERT syntax I believe. I remember using that a while ago, and it suddenly not working. (it worked when using the (column) VALUES() syntax) but according to the manual, both syntaxes are valid. Perhaps the insert into thing has something to do with strict mode being on or off. I'll look that up and see true enough. i'm not 100% on my overall SQL configuration on my localhost, so i'm not sure as to what extensions/values, etc., i might have turned on or off. gonna look into a little further though. i have echo'd both and they are both over 1 Quote Link to comment https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/#findComment-971456 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.