Jump to content

Recommended Posts

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));	
            }

 

Link to comment
https://forums.phpfreaks.com/topic/183997-anything-wrong-with-these-queries/
Share on other sites

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.

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

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.

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.

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.

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

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.

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)?

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

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.