kingb00zer Posted January 18, 2012 Share Posted January 18, 2012 Hi I have got the first part (attacks out) to insert but the part under "target details" where I try to insert the attacks in bit will not insert into the database. I cant understand why it is basically the same as the attacks out part which inserts just fine. // add message to attacks out $message= " You win! Your <b>$thuga</b> thugs with <b>$ak47a</b> AK47's and <b>$pistola</b> pistols killed <b>$deadthugs</b> thugs of your targets <b>$thugb</b> thugs. <br /> You lost <b>$dead3</b> thugs during the battle... <br /> Your thugs stole <b>$$loot</b> from your target. <br /> $win "; $msg= " You Invaded $target\\'s house and won, Your $thuga thugs with $ak47a AK47s and $pistola pistols killed $deadthugs thugs of your targets $thugb thugs. You lost $dead3 thugs during the battle... Your thugs stole $$loot from your target. $win ";$query2 = mysql_query("SELECT * FROM messages WHERE category='attacksout' AND sender='$username'");$rowcount= mysql_num_rows($query2);$rowcount++ ;mysql_query("INSERT INTO messages (recipient, sender, message, category, count) VALUES ('$target', '$username', '$msg', 'attacksout', '$rowcount')");// add to wanted levelinclude('wantedup.php'); // - ---TARGET DETAILS---$newthugsb= $thugb - $deadthugs;$newcashb= $cashb - $loot ; mysql_query("UPDATE playerstats SET thugs= '$newthugsb' WHERE username='" . $_POST['target'] . "'"); mysql_query("UPDATE playerstats SET money= '$newcashb' WHERE username='" . $_POST['target'] . "'");// - kills: $thugkillsb= thugkills + $dead3 (stats)// - thugs dead: $deadcountb= thugsdead + $deadthugs (stats) // - check to see if target was claiming turf from player, if so turf war ends // add message to attacks in... THE ATTACKS IN WILL NOT INSERT!$msg2= " $username invaded your house with $thuga thugs armed with $ak47a AK47s and $pistola pistols. $deadthugs of your $thugb thugs died in the battle. You managed to kill $dead3 of $username\\'s thugs during the battle... $username stole $$loot from you. ";$query3 = mysql_query("SELECT * FROM messages WHERE category='attacksin' AND recipient='$target'");$rowcount2= mysql_num_rows($query3);$rowcount2++ ;mysql_query("INSERT INTO messages (recipient, sender, message, category, count) VALUES ('$target', '$username', '$msg2', 'attacksin', '$rowcount2')"); Link to comment Share on other sites More sharing options...
birbal Posted January 18, 2012 Share Posted January 18, 2012 check the mysql_error() what it is saying for failure Link to comment Share on other sites More sharing options...
kingb00zer Posted January 18, 2012 Author Share Posted January 18, 2012 It has no error, thats the part that confuses me. I had trouble with the first quote of the "attacks out" section but it turned out that i needed to put \\ next to my apostraphies. EDIT: A friend of mine pointed out that in perl you can trap mysql errors, Im trying to find soething like that in php but so far havig no luck. But this does sound like the way to pinpoint this problem. Any suggestions on how to trap the error? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2012 Share Posted January 18, 2012 mysql_query returns false if there was an error. If it returns false, then you use mysql_error like birbal mentioned to get the error message. mysql_query(...) or exit(mysql_error()); Link to comment Share on other sites More sharing options...
kingb00zer Posted January 19, 2012 Author Share Posted January 19, 2012 ohhh I see it says "Duplicate entry '2012-01-19 14:12:21' for key 'PRIMARY'". So I commented lined out the first insert and the second insert worked just fine, but it is important that I get both inserted as a result of this script being run. I'm going to play around with a few ideas that came to mind just now and see how I go. Thanks guys, always a great help Link to comment Share on other sites More sharing options...
justsomeguy Posted January 19, 2012 Share Posted January 19, 2012 It sounds like you need a different primary key, most of the time the primary key is just an autonumber integer field. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.