Jump to content

Help with my attacking script


werny

Recommended Posts

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..

Link to comment
Share on other sites

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



?>




Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.