It is currently Thu Mar 28, 2024 8:38 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PHP Help
PostPosted: Fri Oct 27, 2006 2:59 am 
Noobie
Noobie

Joined: Mon Jun 05, 2006 10:31 pm
Posts: 10
I'm having some trouble. In this arena I am making I used to get very wierd numbers, now that I added else as a die statement I dont get anything. I would like some help on this.

I used to get numbers between 1 and 22
Now with the die statement I get Error!!!!!!!! of course. But I want the arena to work based on str/att/def levels.

Code:
<?php
$usercookie = $_COOKIE['user'];
$rmonster = '1';
$q = "SELECT name,hits,strength,accuracy,defense FROM Arena_Monsters WHERE id = '$rmonster'";
$fight = mysql_query($q);
$row = mysql_fetch_row($fight);
$monster = $row[0];
$mhits = $row[1];
$mstrength = $row[2];
$maccuracy = $row[3];
$mdefense = $row[4];
$mxp = $row[5];
?>
<table align="center" width="75%" style="border: #8D6D4D 1px solid;">
<tr>
  <td bgcolor="#d2b038" align="center"><b>FIGHT!</b></td>
</tr>
<tr>
  <td bgcolor="#e3cc80" align="center">
<?php
echo "Monster name: " . $monster . "<p />";
echo "Hits: " . $mhits . "<p />";
echo "Strength: " . $mstrength . "<p />";
echo "Accuracy: " . $maccuracy . "<p />";
echo "Defense: " . $mdefense . "<p />";
echo "<hr>";
$q2 = "SELECT username,hits,strength,accuracy,defense,xp FROM Arena WHERE username = '$usercookie'";
$character = mysql_query($q2);
$row2 = mysql_fetch_row($character);
$fighter = $row2[0];
$hits = $row2[1];
$strength = $row2[2];
$accuracy = $row2[3];
$defense = $row2[4];
$xp = $row2[5];
echo "Username: " . $fighter . "<p />";
echo "Hits: " . $hits . "<p />";
echo "Strength: " . $strength . "<p />";
echo "Accuracy: " . $accuracy . "<p />";
echo "Defense: " . $defense . "<p />";
echo "<hr>";
while($hits > 0 && $mhits > 0) {
if($strength < 5) {
$rndhit = rand(1, 2);
}
if($strength > 4 && $strength < 10) {
$rndhit = rand(1, 4);
}
if($strength > 9 && $strength < 20) {
$rndhit = rand(1, 7);
}
if($strength > 19 && $strength < 40) {
$rndhit = rand(1, 11);
}
if($strength > 39 && $strength < 80) {
$rndhit = rand(1, 16);
}
if($strength > 79 && $strength < 100) {
$rndhit = rand(1, 22);
}
else {
echo "ERROR!!!!!!!!!!!!";
die;
}
$mon1hit = rand(1, 3);
echo $usercookie . " hits a " . $rndhit . " on " . $monster . ".<p>";
$mhits = $mhits - $rndhit;
echo $monster . " hits a " . $mon1hit . " on " . $usercookie . ".<p>";
$hits = $hits - $mon1hit;
echo "<b>" . $usercookie . "</b>: " . $hits . " <b>" . $monster . "</b>: " . $mhits;
echo "<hr>";
}
?></td>
</tr>
</table>
<?php } ?>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 9:12 pm 
Noobie
Noobie

Joined: Mon Jun 05, 2006 10:31 pm
Posts: 10
Well... now I have a new problem. My database information doesn't update with the following code:

Code:
<?php
include('database.php');
$page = $_REQUEST['page'];

if($page == "login") {
$username = $_POST['username'];
$password = $_POST['password'];
if($username == '' || $password == '') {
?>
<table align="center" width="75%" style="border: #8D6D4D 1px solid;">
<tr>
  <td bgcolor="#d2b038" align="center"><b>ERROR!</b></td>
</tr>
<tr>
  <td bgcolor="#e3cc80" align="center">You must enter a username and password!</td>
</tr>
</table>
<?php
die;
}
$q = "SELECT username FROM Arena WHERE username = '$username' AND password = '$password'";
$result = mysql_query($q);
if(mysql_num_rows($result) == '1') {
setcookie('user',$username,84000);
header('location: index.php?file=mfront');
}
else {
?>
<table align="center" width="75%" style="border: #8D6D4D 1px solid;">
<tr>
  <td bgcolor="#d2b038" align="center"><b>ERROR!</b></td>
</tr>
<tr>
  <td bgcolor="#e3cc80" align="center">Your username/password is nonexistent or invalid!</td>
</tr>
</table>
<?php
}
}
if($page == 'logout') {
setcookie('user',null,-1);
header('location:index.php?file=front');
}
if($page == 'fight1') {
$usercookie = $_COOKIE['user'];
$rmonster = mt_rand(1,2);
$q = "SELECT name,hits,strength,accuracy,defense,xp FROM Arena_Monsters WHERE id = '$rmonster'";
$fight = mysql_query($q);
$row = mysql_fetch_row($fight);
$monster = $row[0];
$mhits = $row[1];
$mstrength = $row[2];
$maccuracy = $row[3];
$mdefense = $row[4];
$mxp = $row[5];
?>
<table align="center" width="75%" style="border: #8D6D4D 1px solid;">
<tr>
  <td bgcolor="#d2b038" align="center"><b>FIGHT!</b></td>
</tr>
<tr>
  <td bgcolor="#e3cc80" align="center">
<?php
echo "Monster name: " . $monster . "<p />";
echo "Hits: " . $mhits . "<p />";
echo "Strength: " . $mstrength . "<p />";
echo "Accuracy: " . $maccuracy . "<p />";
echo "Defense: " . $mdefense . "<p />";
echo "XP: " . $mxp . "<p />";
echo "<hr>";
$q2 = "SELECT username,hits,strength,accuracy,defense,xp FROM Arena WHERE username = '$usercookie'";
$character = mysql_query($q2);
$row2 = mysql_fetch_row($character);
$fighter = $row2[0];
$hits = $row2[1];
$strength = $row2[2];
$accuracy = $row2[3];
$defense = $row2[4];
$xp = $row2[5];
echo "Username: " . $fighter . "<p />";
echo "Hits: " . $hits . "<p />";
echo "Strength: " . $strength . "<p />";
echo "Accuracy: " . $accuracy . "<p />";
echo "Defense: " . $defense . "<p />";
echo "<hr>";
while($hits > 0 && $mhits > 0) {
if($strength < 5) {
$rndhit = mt_rand(1, 2);
$rndhit = $rndhit + round(($accuracy / 2));
}
elseif($strength > 4 && $strength < 10) {
$rndhit = mt_rand(1, 4);
$rndhit = $rndhit + round(($accuracy / 2));
}
elseif($strength > 9 && $strength < 20) {
$rndhit = mt_rand(1, 7);
$rndhit = $rndhit + round(($accuracy / 2));
}
elseif($strength > 19 && $strength < 40) {
$rndhit = mt_rand(1, 11);
$rndhit = $rndhit + round(($accuracy / 2));
}
elseif($strength > 39 && $strength < 80) {
$rndhit = mt_rand(1, 16);
$rndhit = $rndhit + round(($accuracy / 2));
}
else {
$rndhit = mt_rand(1, 22);
$rndhit = $rndhit + round(($accuracy / 2));
}
$mon1hit = mt_rand(1, 3);
echo $usercookie . " hits a " . $rndhit . " on " . $monster . ".<p>";
$mhits = $mhits - $rndhit;
echo $monster . " hits a " . $mon1hit . " on " . $usercookie . ".<p>";
$hits = $hits - $mon1hit;
echo "<b>" . $usercookie . "</b>: " . $hits . " <b>" . $monster . "</b>: " . $mhits;
echo "<hr>";
}
if($hits < 1) {
echo "The " . $monster . "has killed you!";
echo "You have died. You will be automatically revived when you<p>";
echo "go <a href='index.php?file=mfront'>here</a>";
}
if($mhits < 1) {
echo "You have killed a " . $monster . ". You have gained " . $mxp . " experience.<p>";
echo "You have also earned " . $rndgold = mt_rand(1,13) . " gold.";
$q3 = "UPDATE Arena SET xp = 'xp + $mxp',gold = '$rndgold' WHERE 'username' = '$fighter'";
$run = mysql_query($q3) or die("Could not run query.");
}
?></td>
</tr>
</table>
<?php } ?>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 28, 2006 4:33 am 
Noobie
Noobie

Joined: Mon Jun 05, 2006 10:31 pm
Posts: 10
Well, I have that fixed now...and secondly, on another forum they already told me that :)

Apparently the part that wasn't working was beause of the INT values of xp and gold.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
100WebSpace © 2011