Jiraiya Posted December 6, 2008 Share Posted December 6, 2008 im not sure whats wrong with this script its supposed to be a fighting script and i had it kinda working before but im not sure whats wrong with it session_start(); if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href=\"Attack.php? Action=Attack" . $Show['npcname'] . "\">" . $Show['npcname'] . "</a><br>"; } exit(); } $NPC = mysql_escape_string($_GET['NPC']); echo "<a href=\"Attack?NPC=" . $NPC . "&Action=Attack\">Attack</a><br> <a href=\"Attack?NPC=" . $NPC . "&Action=Run\">Run</a><br>"; $username = $_COOKIE['ID_my_site']; if(isset($_COOKIE['NPC'])) { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $UserH = $_COOKIE['health']; $UserA = $UserS['skill']; $UserA *= .1; $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); $NPCH = $_COOKIE['NPCH']; $NPCA = $NPCS['dmg']; $NPCA *= .1; $NPCX = $NPCS['skillgained']; $NPCH -= $UserA; if($NPCH <= 0) { echo "You win and have gained " . $NPCX . " skill"; $UserA = $UserS['skill'] + $NPCX; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('NPCH', $NPCH, 2400); $UserH -= $NPCA; if($UserH <= 0) { echo "You have lost"; $UserA = $UserA * .95; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('health', $UserH, 2400); } else { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); setcookie('NPC', $NPC, 2400); setcookie('health', $UserS['health'], 2400); setcookie('skill', $UserS['skill'], 2400); setcookie('NPCH', $NPCS['health'], 2400); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/ Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 Do you have any error messages? What's happening and what's meant to be happening, some details would help Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-707720 Share on other sites More sharing options...
Jiraiya Posted December 6, 2008 Author Share Posted December 6, 2008 its supposed to be a player vs computer controlled fighting like and a reward system all built into one script Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708103 Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 and what's wrong with it, what doesn't ahppen and is there an error messsage? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708116 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 when i run it it says you havent picked a npc to fight even when i do pick one Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708923 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 When asking for help with a script it is always advisable to supply as much information as possible. You know what your script should or shouldn't be doing - we're not psychics or magicians and when looking at others' code need to know a little more than "it isn't working" Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708926 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 Is NPC set in a cookie? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708932 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 the script is supposed to take player data player health "A" and skill "B" and then subtract 10% of "B" from "C" which is computer controlled enemy and then take 10% of "D" which is computer controlled enemy skill and subtract that from "A" until either "A" or "C" reaches zero and if "A" reaches zero then 5% of "B" is supposed to be taken away from "B" and if "C" reaches zero then "B" is supposed to gain a preset number to the total of "B". im not sure whats wrong with it all i know is that i keeps telling me that i havent picked a npc to fight Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708937 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 I think it might be set as a cookie im not sure about it im kinda new to using php Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708940 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 NPC looks like it's supplied on the URL going by the $_GET bit... Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708943 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 what do you mean by that? please explain it NPC looks like it's supplied on the URL going by the $_GET bit... Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708947 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 I'm not 100% if this is right seeing as you don't know the code either but try this change <?php if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href="Attack.php? Action=Attack" . $Show['npcname'] . "">" . $Show['npcname'] . "</a><br>"; } exit(); } ?> to this <?php if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href="Attack.php? Action=Attack&NPC=" . $Show['npcname'] . "">" . $Show['npcname'] . "</a><br>"; } exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708950 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 You've got this line: if(!isset($_GET['NPC'])) That is checking if NPC is in the URL but you don't seem to actually read it anywhere. You do also check for a cookie with this line: if(isset($_COOKIE['NPC'])) But again, you don't actually read it. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708951 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 the code that was suggested above just made my page bland Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708954 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 My bad... just saw this line: $NPC = mysql_escape_string($_GET['NPC']); That's reading it off the URL but I can't see you accessing the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708956 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 here is the code i had that sorta worked before it might be easier to fix from this point on i hope <?php session_start(); if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href=\"Attack.php?NPC=" . $Show['npcname'] . "\">" . $Show['npcname'] . "</a><br>"; } exit(); } $NPC = mysql_escape_string($_GET['NPC']); echo "<a href=\"Attack?NPC=" . $NPC . "&Action=Attack\">Attack</a><br> <a href=\"Attack?NPC=" . $NPC . "&Action=Run\">Run</a><br>"; $username = $_COOKIE['ID_my_site']; if(isset($_COOKIE['NPC'])) { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $UserH = $_COOKIE['health']; $UserA = $UserS['skill']; $UserA *= .1; $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); $NPCH = $_COOKIE['NPCH']; $NPCA = $NPCS['dmg']; $NPCA *= .1; $NPCX = $NPCS['skillgained']; $NPCH -= $UserA; if($NPCH <= 0) { echo "You win and have gained " . $NPCX . " skill"; $UserA = $UserS['skill'] + $NPCX; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('NPCH', $NPCH, 2400); $UserH -= $NPCA; if($UserH <= 0) { echo "You have lost"; $UserA = $UserA * .95; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('health', $UserH, 2400); } else { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); setcookie('NPC', $NPC, 2400); setcookie('health', $UserS['health'], 2400); setcookie('skill', $UserS['skill'], 2400); setcookie('NPCH', $NPCS['health'], 2400); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708960 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 What is the entire URL calling this script - I'm particularly interested in the end... Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708964 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 here is the url were this script should running http://narutotalesofthesannin.com/Attack.php here is the entire code for the page <?php mysql_connect("localhostl", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); session_start(); if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href=\"Attack.php?NPC=" . $Show['npcname'] . "\">" . $Show['npcname'] . "</a><br>"; } exit(); } $NPC = mysql_escape_string($_GET['NPC']); echo "<a href=\"Attack?NPC=" . $NPC . "&Action=Attack\">Attack</a><br> <a href=\"Attack?NPC=" . $NPC . "&Action=Run\">Run</a><br>"; $username = $_COOKIE['ID_my_site']; if(isset($_COOKIE['NPC'])) { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $UserH = $_COOKIE['health']; $UserA = $UserS['skill']; $UserA *= .1; $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); $NPCH = $_COOKIE['NPCH']; $NPCA = $NPCS['dmg']; $NPCA *= .1; $NPCX = $NPCS['skillgained']; $NPCH -= $UserA; if($NPCH <= 0) { echo "You win and have gained " . $NPCX . " skill"; $UserA = $UserS['skill'] + $NPCX; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('NPCH', $NPCH, 2400); $UserH -= $NPCA; if($UserH <= 0) { echo "You have lost"; $UserA = $UserA * .95; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('health', $UserH, 2400); } else { $UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserS); $NPCS = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCS); setcookie('NPC', $NPC, 2400); setcookie('health', $UserS['health'], 2400); setcookie('skill', $UserS['skill'], 2400); setcookie('NPCH', $NPCS['health'], 2400); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708965 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 try this <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); session_start(); if(!isset($_GET['NPC'])) { echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href=\"Attack.php?NPC={$Show['npcname']}\">{$Show['npcname']}</a><br>"; } exit(); } $NPC = mysql_real_escape_string($_GET['NPC']); echo "<a href=\"Attack.php?NPC=" . $NPC . "&Action=Attack\">Attack</a><br> <a href=\"Attack.php?NPC=" . $NPC . "&Action=Run\">Run</a><br>"; $username = $_COOKIE['ID_my_site']; if(isset($_COOKIE['NPC'])) { $UserSQuery = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserSQuery); $UserH = $_COOKIE['health']; $UserA = $UserS['skill']; $UserA *= .1; $NPCSQuery = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCSQuery); $NPCH = $_COOKIE['NPCH']; $NPCA = $NPCS['dmg']; $NPCA *= .1; $NPCX = $NPCS['skillgained']; $NPCH -= $UserA; if($NPCH <= 0) { echo "You win and have gained " . $NPCX . " skill"; $UserA = $UserS['skill'] + $NPCX; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('NPCH', $NPCH, 2400); $UserH -= $NPCA; if($UserH <= 0) { echo "You have lost"; $UserA = $UserA * .95; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('health', $UserH, 2400); } else { $UserSQuery = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserSQuery); $NPCSQuery = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCSQuery); setcookie('NPC', $NPC, 2400); setcookie('health', $UserS['health'], 2400); setcookie('skill', $UserS['skill'], 2400); setcookie('NPCH', $NPCS['health'], 2400); } ?> </body> </html> Made a lot of little changes!! Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708971 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 When I first run that I get a list of who to fight. When I click one it then refreshes giving me "Attack" and "Run" Clicking both "Attack" and "Run" seems to do nothing. What should it be doing? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708973 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 when you click attack it should run the script that does the fighting when you press run it should bring you to the travel page Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708974 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Try and run this - when you click "Attack" which number appears? <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); session_start(); if(!isset($_GET['NPC'])) { echo "1"; echo "You have not selected a NPC to fight! Please select one from below <br><br>"; $NPCS = mysql_query("SELECT * FROM `npc`"); while($Show = mysql_fetch_array($NPCS)) { echo "<a href=\"Attack.php?NPC={$Show['npcname']}\">{$Show['npcname']}</a><br>"; } exit(); } $NPC = mysql_real_escape_string($_GET['NPC']); echo "<a href=\"Attack.php?NPC=" . $NPC . "&Action=Attack\">Attack</a><br> <a href=\"Attack.php?NPC=" . $NPC . "&Action=Run\">Run</a><br>"; $username = $_COOKIE['ID_my_site']; if(isset($_COOKIE['NPC'])) { echo "2"; $UserSQuery = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserSQuery); $UserH = $_COOKIE['health']; $UserA = $UserS['skill']; $UserA *= .1; $NPCSQuery = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCSQuery); $NPCH = $_COOKIE['NPCH']; $NPCA = $NPCS['dmg']; $NPCA *= .1; $NPCX = $NPCS['skillgained']; $NPCH -= $UserA; if($NPCH <= 0) { echo "You win and have gained " . $NPCX . " skill"; $UserA = $UserS['skill'] + $NPCX; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('NPCH', $NPCH, 2400); $UserH -= $NPCA; if($UserH <= 0) { echo "You have lost"; $UserA = $UserA * .95; mysql_query("UPDATE `users` SET skill='$UserA' WHERE username='$username'"); unset($_COOKIE['NPC']); exit(); } setcookie('health', $UserH, 2400); } else { echo "3"; $UserSQuery = mysql_query("SELECT * FROM `users` WHERE username='$username'"); $UserS = mysql_fetch_array($UserSQuery); $NPCSQuery = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); $NPCS = mysql_fetch_array($NPCSQuery); setcookie('NPC', $NPC, 2400); setcookie('health', $UserS['health'], 2400); setcookie('skill', $UserS['skill'], 2400); setcookie('NPCH', $NPCS['health'], 2400); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708986 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 when i click attack the number 3 appears Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708988 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 @Yesideez Glad someone saw my post Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708990 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Now we can see where the code is running - this is telling me that the cookie is NOT set otherwise we'd get "2" appearing and some other form of output. If you look inside the "3" section you can see you're not sending anything to the browser so in effect it is doing what it's told. What should the cookie "NPC" contain? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/#findComment-708991 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.