Tylor_Famous Posted March 6, 2008 Share Posted March 6, 2008 Ok I am working on a SIMPLE game where you feed a dog and walk it and stuff. There are two bars (one for health and the other for how clean the dog is) and I want the bars to change when you take it for a walk and stuff. Simple so far... I have a "pre-game" page where you pick your dog. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="post" action="dog.php"> <select name="dognames"> <option value="Goldy">Goldy</option> </select> <input type="submit" name="button" id="button" value="Submit" /> <input name="health" type="hidden" value="100" /> <input name="cleanness" type="hidden" value="100" /> </form> </body> </html> Then the php page with all the code.... <?php $name = "Golen"; $health = $_POST['health']; $cleanness = $_POST['health']; $words = "I love you"; $action = "walk"; $mood = "Happy"; if ($_POST['food'] == 'bone'){ $health = $health + 2; $cleanness = $cleanness - 2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style> #health{ width:100%; border:#990000 solid 2px; height:6px; } #healthbar{ background-color:#FF0000; height:6px; width:<?php echo $health; ?>%; } #cleanness{ width:100%; border:#000066 solid 2px; height:6px; } #cleanbar{ background-color:#0000FF; height:6px; width:<?php echo $cleanness; ?>%; } p{ padding:0px; margin:0px; } </style> </head> <body> <p><img src="dogpictures/dog images/basic_dog_<?php echo $action; ?>.GIF" alt="Your Device Can Not Support Images, Sorry" /><br /></p> <p>Health <?php echo $health; ?>%<div id="health"><div id="healthbar"></div></div></p> <p>Cleanness: <?php echo $cleanness; ?>%<div id="cleanness"><div id="cleanbar"></div></div></p> <p>Mood: <?php echo $mood; ?></p> <p><?php echo $name; ?> says: "<?php echo $words; ?>"</p> <br /> <form action="<?=$PHP_SELF?>" method="post"> <p>Action:<select name="food" size="1"> <option value="walk">Take On walk</option> <option value="brush">Brush</option> <option value="pet">Pet</option> <option value="bath">Give Bath</option> </select> <input name="Submit" type="submit" value="Submit" /> </form> </p> <br /> <form action="<?=$PHP_SELF?>" method="post"> <p>Action:<select name="food" size="1"> <option value="bone">Dog Bone</option> <option value="steak">Steak</option> <option value="water">Water</option> <option value="dogfood">Dog Food</option> </select> <input name="Submit" type="submit" value="Submit" /> </form> </p> </body> </html> I am jsut working $health and $cleanness right now. I want to press "bone" (from the dropdown menu) and have it bring up the health by 2 and the $cleanness down by 2. The code where this should work is... <?php if ($_POST['food'] == 'bone'){ $health = $health + 2; $cleanness = $cleanness - 2; } ?> But of course it isn't working. Infact it seemes to lose it or something because the value of $health (which I can see through the echo) gose away after I feed my dog a bone. I am new and have little idea what I am doing so any help would be GREAT! Link to comment https://forums.phpfreaks.com/topic/94629-ok-newbie-needs-some-help-over-here/ Share on other sites More sharing options...
Tylor_Famous Posted March 6, 2008 Author Share Posted March 6, 2008 Am I going about this idea all wrong? :-\ Link to comment https://forums.phpfreaks.com/topic/94629-ok-newbie-needs-some-help-over-here/#findComment-485260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.