werny Posted August 30, 2007 Share Posted August 30, 2007 I can't figure out how to get this to work <?php require_once 'appinclude.php'; $con = mysql_connect("myhost","myaccount","mypassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM members WHERE id='$user'"); $row = mysql_fetch_assoc($result); $attackroll = $row['attackroll']; $defendroll = $row['defendroll']; $defendwin = "$defendroll"-"$attackroll"; $attackwin = "$attackroll"-"$defendroll"; $attackerpower = $row['attackpower']; $defendpower = $row['cpudefense']; $defendupdate = "$attackerpower"-"$defendwin"; $attackupdate = "$defendpower"-"$attackwin"; $numbattacker = rand(1,6); $numbdefender = rand(1,6); echo "you rolled a $numbattacker The enemy rolled a $numbdefender <br />"; $query = "UPDATE members SET attackroll = '$numbattacker' WHERE id='$user'"; mysql_query($query); $query = "UPDATE members SET defendroll = '$numbdefender' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result); if ("$attackroll"<"$defendroll") echo "you lose"; $query = "UPDATE members SET attackpower = '$defendupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result); if ("$attackroll">"$defendroll") echo "you win!"; $query = "UPDATE members SET cpudefense = '$attackupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result); ?> it will show what you and the computer rolled, but it won't insert the values correctly.. Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/ Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 if ("$attackroll">"$defendroll") You're comparing strings here. Take out the quotes around them to compare numbers. Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-337826 Share on other sites More sharing options...
werny Posted August 31, 2007 Author Share Posted August 31, 2007 still doesnt work, it just wont actually update the winners army, or the defenders army with the losses, it is making me mad Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338344 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 try <?php $attackroll = $row[attackroll]; $defendroll = $row[defendroll]; $defendwin = $defendroll-$attackroll; $attackwin = $attackroll-$defendroll; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338347 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 Where are the curly braces? Shouldnt the code be like: if($a<$b){ //blah blah } else{ //some other blah blah } Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338348 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 try <?php $attackroll = $row[attackroll]; $defendroll = $row[defendroll]; ?> Returned indexes are strings so that will not work. Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338349 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 Like jesirose suggested take the "" out. Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338350 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 Try: <?php require_once 'appinclude.php'; $con = mysql_connect("myhost","myaccount","mypassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM members WHERE id='$user'"); $row = mysql_fetch_assoc($result); $attackroll = $row['attackroll']; $defendroll = $row['defendroll']; $defendwin = $defendroll-$attackroll; $attackwin = $attackroll-$defendroll; $attackerpower = $row['attackpower']; $defendpower = $row['cpudefense']; $defendupdate = $attackerpower-$defendwin; $attackupdate = $defendpower-$attackwin; $numbattacker = rand(1,6); $numbdefender = rand(1,6); echo "you rolled a $numbattacker The enemy rolled a $numbdefender <br />"; $query = "UPDATE members SET attackroll = '$numbattacker' WHERE id='$user'"; mysql_query($query); $query = "UPDATE members SET defendroll = '$numbdefender' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result); if ($attackroll<$defendroll){ echo "you lose"; $query = "UPDATE members SET attackpower = '$defendupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result);} if ($attackroll>$defendroll){ echo "you win!"; $query = "UPDATE members SET cpudefense = '$attackupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result);} ?> Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338351 Share on other sites More sharing options...
werny Posted August 31, 2007 Author Share Posted August 31, 2007 Try: <?php require_once 'appinclude.php'; $con = mysql_connect("myhost","myaccount","mypassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM members WHERE id='$user'"); $row = mysql_fetch_assoc($result); $attackroll = $row['attackroll']; $defendroll = $row['defendroll']; $defendwin = $defendroll-$attackroll; $attackwin = $attackroll-$defendroll; $attackerpower = $row['attackpower']; $defendpower = $row['cpudefense']; $defendupdate = $attackerpower-$defendwin; $attackupdate = $defendpower-$attackwin; $numbattacker = rand(1,6); $numbdefender = rand(1,6); echo "you rolled a $numbattacker The enemy rolled a $numbdefender <br />"; $query = "UPDATE members SET attackroll = '$numbattacker' WHERE id='$user'"; mysql_query($query); $query = "UPDATE members SET defendroll = '$numbdefender' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result); if ($attackroll<$defendroll){ echo "you lose"; $query = "UPDATE members SET attackpower = '$defendupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result);} if ($attackroll>$defendroll){ echo "you win!"; $query = "UPDATE members SET cpudefense = '$attackupdate' WHERE id='$user'"; mysql_query($query); mysql_fetch_assoc($result);} ?> tried and still the results in the database are messed up, sometimes it adds, and sometimes it takes away troops from the database, I am just tempted sometimes to make a database that I dont care about and give someone the password and help me out... Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338354 Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 i pmed you on yahoo but no response Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338357 Share on other sites More sharing options...
werny Posted August 31, 2007 Author Share Posted August 31, 2007 i pmed you on yahoo but no response im not seeing it, send it to my main email, poopsmith_rules@hotmail.com Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338358 Share on other sites More sharing options...
AndyB Posted August 31, 2007 Share Posted August 31, 2007 If that's the whole script, where does the variable $user come from? Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338491 Share on other sites More sharing options...
Timma Posted August 31, 2007 Share Posted August 31, 2007 I highly doubt they want to post the script for their entire game. Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338538 Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 i'm sure AndyB was talking about the script of the file in question.. not the script to the whole project! Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338542 Share on other sites More sharing options...
Timma Posted August 31, 2007 Share Posted August 31, 2007 Yes, he may be asking that, but... require_once 'appinclude.php'; Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338553 Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 in which case the reply would be from "appinclude.php", remember if you assume something you make an ass out of u and me lol Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-338556 Share on other sites More sharing options...
werny Posted September 1, 2007 Author Share Posted September 1, 2007 Yes, he may be asking that, but... require_once 'appinclude.php'; yeah its made in for facebook, so $user is defined the in included files, that isnt the problem Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-339131 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 From what i saw your script was working correctly? what exactly do you mean it isnt adding up right? ??? Quote Link to comment https://forums.phpfreaks.com/topic/67336-help-with-my-attacking-script/#findComment-339139 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.