Need someone to look through some of my code - big problem
Moderator: General Moderators
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
Need someone to look through some of my code - big problem
Ok, im having trouble now, its been like 5 days, and I can't figure this thing out
I know you get this problem from either having a </div> end tag without a start tag for it
or the other way around <div blah> without end tag
and also if I delete the entire attack section from 'if (isset($_POST['attack']))'
to its last '}' then it stops, (so does the whole attack function too -.-)
I've tried deleting and re-adding the same code as I go, i've gone through the whole thing, and it didnt work...
Can someone help plz?
I can post my 3 databases it uses and my 2 documents it uses (HP is the main part) and is included in 'indexg'
HP is only 800-900 lines long, and the area of the problem about 70 (takes 20 seconds)
I just cant seem to figure this out... and I cant progress without getting past this... because it makes my page look totally screwed up, can someone please help me! I've gone through it atleast 50 times, with 7 different editors, from very advanced ones to text document,
Problem area starts from if (isset($_POST['attack'])) (marked [A1]), and finishes at } (marked [A1])
if someones willing to help me i'll be very greatful!
(if you have msn/icq/aim/yahoo I can send files over their, otherwise if not, tell me)
I know you get this problem from either having a </div> end tag without a start tag for it
or the other way around <div blah> without end tag
and also if I delete the entire attack section from 'if (isset($_POST['attack']))'
to its last '}' then it stops, (so does the whole attack function too -.-)
I've tried deleting and re-adding the same code as I go, i've gone through the whole thing, and it didnt work...
Can someone help plz?
I can post my 3 databases it uses and my 2 documents it uses (HP is the main part) and is included in 'indexg'
HP is only 800-900 lines long, and the area of the problem about 70 (takes 20 seconds)
I just cant seem to figure this out... and I cant progress without getting past this... because it makes my page look totally screwed up, can someone please help me! I've gone through it atleast 50 times, with 7 different editors, from very advanced ones to text document,
Problem area starts from if (isset($_POST['attack'])) (marked [A1]), and finishes at } (marked [A1])
if someones willing to help me i'll be very greatful!
(if you have msn/icq/aim/yahoo I can send files over their, otherwise if not, tell me)
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
hmm
Ok
If I completely delete this code out of it, nothing happens (including the bad part)
not sure if this is exactly a snippet but o well:P
If I completely delete this code out of it, nothing happens (including the bad part)
not sure if this is exactly a snippet but o well:P
Code: Select all
if (isset($_POST['attack']))
{//[A1]
if ($currlifemon < 1)
{
?>
<div style='Position: absolute; top: 200; left: 325;'>
<table border="3" width="325"> <tr> <td align="center">
<?php
echo '<b>The monster is dead</b>';
?>
</div>
</td> </tr> </table>
<?php
$mhs=true;
}
?>
</div>
</font>
<?php
if ($currlifemon >= 1) //[C1]
{
//a2
if ($_POST['attack']=='attk') //[A2]
{
/*echo '<div style="position: absolute; top:125; left:430;">
<object width="100" height="100" param name="wmode" value="transparent">
<param name="Baby Elf" value="Baby Elf.swf">
<embed wmode="transparent" src="Baby Elf.swf" width="100" height="100">
</embed>
</object>
</div>'; */
?>
<div style='Position: absolute; top: 200; left: 325;'>
<?php
if ($phd==false)
{//[PHD1]
?>
<table border='3' width='325'>
<tr>
<td align='center'>
<?php
$currmonster=$row['currmonster'];
$currmonster=$currmonster+1;
echo '<b>Level '.$currmonster.' '. $mon1[$currmonster-1].'</b><br />';
echo '<b>You attack a '.$mon1[$currmonster-1]. ':</b><br />';
$currmonster=$currmonster-1;
///////////Below is loading monster string and text for dmg and so on
///////////////////////////////////////////////////////////////////////////////////////
//CLEAR ABOVE
$sa=true;
$mlmon=$currmonster+1;
$strlvlmon=$mlmon * 4;
$strdmgmon=$strlvlmon / 4;
$strdmgmon=rand(0, $strdmgmon * 1.3);
$strdmgmon=round($strdmgmon);
//strength
$dexlvlmon=$mlmon * 5;
$dexcthmon=rand($dexlvlmon - $dexlvl, 100);
$dexcth=rand($dexlvl - $dexlvlmon, 100);
//$dexcthmon=$dexcthmon/100;
$_SESSION['lc']=$currlifemon;//$_SESSION['lc']+$currlifemon;
//dexterity
$currlifemon=$mlmon * 13;
$_SESSSION['lc2']=$currmaxlifemon;//$_SESSION['lc2']+$currlifemon;
$currmaxlifemon=$mlmon * 13;
$currlifemon=$_SESSION['lc'];
//life
$deflvlmon=$mlmon * 3;
//defense
$defdamon=$mlmon * $deflvlmon;
$defdamon=$defdamon/15;
//int
$intlvlmon=$mlmon * 4;
//focus
$foclvlmon=$mlmon * 4;
//mag
$magmon=$mlmon * 9;
$magmaxmon=$mlmon * 9;
mysql_query("UPDATE chars SET currmonster = $currmonster
WHERE idcount=$id")or die('Error: Q6'.mysql_error());
mysql_close($con);
//monsters below
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("monsters", $con);
mysql_query("UPDATE m_l SET currlifemon = $currmaxlifemon
")or die('Error: 40'.mysql_error());
mysql_query("UPDATE m_l SET strlvlmon = $strlvlmon
")or die('Error: 41'.mysql_error());
mysql_query("UPDATE m_l SET strdmgmon = $strdmgmon
")or die('Error: 42'.mysql_error());
mysql_query("UPDATE m_l SET dexlvlmon = $dexlvlmon
")or die('Error: 43'.mysql_error());
mysql_query("UPDATE m_l SET dexcthmon = $dexcthmon
")or die('Error: 44'.mysql_error());
mysql_query("UPDATE m_l SET currlifemon = $currlifemon
")or die('Error: 45'.mysql_error());
mysql_query("UPDATE m_l SET currmaxlifemon = $currmaxlifemon
")or die('Error: 46'.mysql_error());
mysql_query("UPDATE m_l SET deflvlmon = $deflvlmon
")or die('Error: 47'.mysql_error());
mysql_query("UPDATE m_l SET defdamon = $defdamon
")or die('Error: 48'.mysql_error());
mysql_query("UPDATE m_l SET intlvlmon = $intlvlmon
")or die('Error: 49'.mysql_error());
mysql_query("UPDATE m_l SET foclvlmon = $foclvlmon
")or die('Error: 50'.mysql_error());
mysql_query("UPDATE m_l SET magmon = $magmon
")or die('Error: 51'.mysql_error());
mysql_query("UPDATE m_l SET magmaxmon = $magmaxmon
")or die('Error: 52'.mysql_error());
//if ($dexcth > $dexcthmon)
//{
echo "You attack with your ".$weapon." and hit for ".$strdmg." damage";
$currlifemon=$currlifemon-$strdmg;
//}
//else
//{
//echo "You attack with your ".$weapon." and you miss"; $strdmg=0;
//}
echo '<br /> Current Life is '.$currlifemon. '<br />';
$dexcthmon=rand($dexlvlmon - $dexlvl, 100);
$dexcth=rand($dexlvl - $dexlvlmon, 100);
//if ($dexcthmon > $dexcth)
//{
echo '<b>'.$mon1[$currmonster]. "</b> attacks you and hits you for ".$strdmgmon." damage";
$currlife=$currlife-$strdmgmon;
//}
//else
//{
//echo '<b>'.$mon1[$currmonster]. "</b> attacks you and misses"; $strdmgmon=0;
//}
}//[PHD1]]
?>
</td>
</tr>
</table>
</font>
</div>
<?php
///////////Levels and XP below////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//boolean value when click attack '$bak=true;' when cast '$bca=true;' also make sure I set each
//to false other
if ($phd==false)
{//[PHD2]
if ($tstr==true)
{
$strxp=$strxp+$strdmg;
}
if ($tdex==true)
{
$dexxp=$dexxp+$strdmg;
}
if ($tdef==true)
{
$defxp=$defxp+$strdmg;
}
if ($tint==true)
{
$intxp=$intxp+$strdmg;
}
if ($tfoc==true)
{
$focxp=$focxp+$strdmg;
}
if ($strxp>=$strlvl * $strdiv * $strlvl)
{
$strlvl=$strlvl+1;
$strdiv=$strdiv+1;
}
if ($dexxp>=$dexlvl * $dexdiv * $dexlvl)
{
$dexlvl=$dexlvl+1;
$dexdiv=$dexdiv+1;
}
if ($defxp>=$deflvl * $defdiv * $deflvl)
{
$deflvl=$deflvl+1;
$defdiv=$defdiv+1;
}
if ($intxp>=$intlvl * $intdiv * $intlvl)
{
$intlvl=$intlvl+1;
$intdiv=$intdiv+1;
}
if ($focxp>=$foclvl * $focdiv * $foclvl)
{
$foclvl=$foclvl+1;
$focdiv=$focdiv+1;
}
}//[PHD2]
?>
<!--</div>-->
<?php
if ($currlife < 1)
{
?>
<DIV STYLE='Position: absolute; Top: 200; Left: 325;'>
<?php
echo '<table border=\'3\' width=\'325\'> <tr> <td align="center"><b><font color=\'maroon\'>You are dead</font></b></td></tr></table>';
$phd=true;
?>
</div>
<?php
}
?>
<?php
}//[A2]
if ($currlifemon < 1)
{
$mhs=true;
$curlifemon=0;
}
if ($mhs==true)
{ //a3
$gold=$gold+$dropgold;
$mhs=false;
$_SESSION['lc']=0;
$_SESSION['lc2']=0;
}
} //[C1]
}//[A1]-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
hmm
it detects if the button being clicked is the 'attack' button
if so
it calculates the value off a dropdown box (1,2,3,4) (which is a monster list)
sets a variabnle called mlmon to it, which is used to calculate str, def, dex, so on, and calculate dmg, chance to hit, damage aborption, then it updates it, decreases monsters life from the dmg you deal (variable strdmg) checks if monster is dead at the end, if so adds gold based off ML, also adds XP to the stat your training (from other buttons you can change) checks if its at a certain point based off your level, then aventurely loads it into MySQL (not shown in this) however it does add somethings...
the HTML code, is in that script
if so
it calculates the value off a dropdown box (1,2,3,4) (which is a monster list)
sets a variabnle called mlmon to it, which is used to calculate str, def, dex, so on, and calculate dmg, chance to hit, damage aborption, then it updates it, decreases monsters life from the dmg you deal (variable strdmg) checks if monster is dead at the end, if so adds gold based off ML, also adds XP to the stat your training (from other buttons you can change) checks if its at a certain point based off your level, then aventurely loads it into MySQL (not shown in this) however it does add somethings...
wahh???post the html code that is output from this as well please
the HTML code, is in that script
Is it just a copy&paste error or is your code really not indented at all? Then it is no wonder you're unable to find any structural error.
e.g.
Why do you use php to echo the static string in this block?And why do you use a table with only one row and cell within a div element?
e.g.
<div><table><tr><td>...</div></td><div style='Position: absolute; top: 200; left: 325;'>
<table border="3" width="325"> <tr> <td align="center">
<?php
echo '<b>The monster is dead</b>';
?>
</div>
</td> </tr> </table>
Why do you use php to echo the static string in this block?
Code: Select all
<div style='Position: absolute; top: 200; left: 325;'>
<table border="3" width="325">
<tr>
<td align="center">
<b>The monster is dead</b>
</td>
</tr>
</table>
</div>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Mythic Fr0st I'm not surprised you aren't able to fix bugs in this case. To fix this problem and prevent future ones like it you should separate logic and database interactions from HTML. If you are familiar with a templating engine, use it. Otherwise seek out something simple like Zend View (you'll have to download the entire framework but you only need to use the view part) tutorial be religious about minimising the amount of logic in the views.
And volka is right you really should be indenting your code, including the HTML. Don't worry about introducing whitespace into your output its more important that you can read your own code.
And volka is right you really should be indenting your code, including the HTML. Don't worry about introducing whitespace into your output its more important that you can read your own code.
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
lol
Considering its only been 15 days, If I was were I am now when I started, I would of, but im learning and making as I go
and 1 table with cell looks pwnage, lol
im kinda not sure how to indent though...
I know what it is, and how to do it in another language I learnt (jass)
but not this one, in jass, it'd basically be 4 indents for everything
and 1 table with cell looks pwnage, lol
im kinda not sure how to indent though...
I know what it is, and how to do it in another language I learnt (jass)
but not this one, in jass, it'd basically be 4 indents for everything
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: lol
<div style="margin:0 0 0 100;">indented 100 on the right "margin:top left bottom right;"</div>Mythic Fr0st wrote:im kinda not sure how to indent though...
(#10850)
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Check out:
http://framework.zend.com/manual/en/cod ... style.html
Also, a good editor will help you maintain your indenting, (cough*editplus*cough) as well as colour-code your source.
http://framework.zend.com/manual/en/cod ... style.html
Also, a good editor will help you maintain your indenting, (cough*editplus*cough) as well as colour-code your source.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
hmm
I have recently gone through my ENTIRE -.- Hp code, and revised it, completely wrote it out from scratch
copying off the old, and dumping any unneeded things (cut 200 lines off it of useless stuff)
Indented, although pretty sure NOT correctly Lol, but hey its easier to read
I have come to the conclusion that it is not HP that is the problem, I belive to be 'indexg.php'
I also have revised that, the problem still is there, -.-
i've replaced <div positioning tags> with this
(css), now, this one works, but all my other 10 dont (First Problem:P)
But i'll make a thread about this, cya in Clientside:P)
now, this is my actual indexg code (for the buttons)
this is a big one, covering my monsters dropdown box, the 'new fight' and attack button (last fight too)
the names in the ' < > ' are from my css code (the names)
now this kinda isnt indented so much, since I dont know how to indent html
above is just, buttons to change what stat you change, str never gets effected, nor newfight
the rest is just navigation and the equipment 'button'
I cant see anything wrong with this, (apart from my css not working O_O)
although if there was something i'd question the dropdown box, it was one thing I kinda scrapped together from unique bits of information from everything lol
Apparently it doesnt move buttons
Any way to do this
copying off the old, and dumping any unneeded things (cut 200 lines off it of useless stuff)
Indented, although pretty sure NOT correctly Lol, but hey its easier to read
I have come to the conclusion that it is not HP that is the problem, I belive to be 'indexg.php'
I also have revised that, the problem still is there, -.-
i've replaced <div positioning tags> with this
Code: Select all
s {
position: absolute;
top: 186px;
left: 760px;
padding: 0 0em;
<!--background: #c00;
color: white;
font-weight: bold;-->
}But i'll make a thread about this, cya in Clientside:P)
now, this is my actual indexg code (for the buttons)
this is a big one, covering my monsters dropdown box, the 'new fight' and attack button (last fight too)
the names in the ' < > ' are from my css code (the names)
Code: Select all
<mdb>
<!--This one here is dropdown box for monsters-->
<form method="post" action="indexg.php">
<select name="monsters">
<option value=0>Baby Elf</option>
<option value=1>Wood Elf</option>
<option value=2>Dark Elf</option>
<option value=3>Blood Elf</option>
</select>
<br />
<input type='hidden' name='nf' value='nf2'>
<input type="submit" value="New Fight">
</form>
<!--this one here is the 'last fight' button, which lets you attack the last monster you attacked-->
<form method="post" action="indexg.php">
<input type='hidden' name='lc1' value='lc2'>
<input type="submit" value="Last Fight">
</form>
<!--This one here is the 'attack' button yes, my most hated button of all-->
<?php
if ($sa==true)
{
?>
<form method="post" action="indexg.php">
<input type='hidden' name='attack' value='attk'>
<input type="submit" value="Attack">
</form>
<?php
}
?>
</mdb>Code: Select all
<tb>
<form method="post" action="indexg.php">
<input type='hidden' name='strBTN' value='Str'>
<input type="submit" value="Str">
</form>
<form method="post" action="indexg.php">
<input type='hidden' name='dexBTN' value='Dex'>
<input type="submit" value="Dex">
</form>
<form method="post" action="indexg.php">
<input type='hidden' name='defBTN' value='Def'>
<input type="submit" value="Def">
</form>
<form method="post" action="indexg.php">
<input type='hidden' name='intBTN' value='Int'>
<input type="submit" value="Int">
</form>
<form method="post" action="indexg.php">
<input type='hidden' name='focBTN' value='Foc'>
<input type="submit" value="Foc">
</form>
</tb>the rest is just navigation and the equipment 'button'
Code: Select all
if ($equipment==false)
{
?>
<se>
<form method="post" action="indexg.php">
<input type='hidden' name='ceq1' value='ceq2'>
<input type="submit" value="Show Equipment">
</form>
</se>
<?php
}
else
{
?>
<he>
<form method="post" action="indexg.php">
<input type='hidden' name='ceq3' value='ceq4'>
<input type="submit" value="Hide Equipment">
</form>
</he>
<?php
}
?>
<n>
<form method="post" action="indexg.php">
<input type='hidden' name='Nth1' value='Nth2'>
<input type="submit" value="North">
</form>
</n>
<s>
<form method="post" action="indexg.php">
<input type='hidden' name='Sth1' value='Sth2'>
<input type="submit" value="South">
</form>
</s>
<w>
<form method="post" action="indexg.php">
<input type='hidden' name='Wst1' value='Wst2'>
<input type="submit" value="West">
</form>
</w>
<e>
<form method="post" action="indexg.php">
<input type='hidden' name='East1' value='East2'>
<input type="submit" value="East">
</form>
</e>
<?phpalthough if there was something i'd question the dropdown box, it was one thing I kinda scrapped together from unique bits of information from everything lol
Apparently it doesnt move buttons
Any way to do this
Last edited by Mythic Fr0st on Mon Dec 25, 2006 4:27 pm, edited 1 time in total.