ryeman98 Posted June 29, 2008 Share Posted June 29, 2008 Can't quite seem to put my finger on it ... :-\ if ($item['feed'] == 1) { $user_pet = mysql_query("SELECT * FROM `user_pets` WHERE owner_id='$user_id'"); while ($pets = mysql_fetch_array($user_pet)) { echo "<br /><br /><a href='/place/item.php?act=eat&pet=".$pets['id']."&id=".$items_id."'>Feed to ".$pets['name']."</a>"; } // End while } // End if if ($_GET['act'] == "eat" && (isset($_GET['pet'])) && (isset($_GET['id']))) { As you can see, there is a link. When the link is clicked, it should go to this if statement here like it does on all of my other pages but since I put 2 issets, it won't go to that if statement. Can't quite figure it out, help is much appreciated. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 29, 2008 Share Posted June 29, 2008 <?php if (isset($_GET['pet']) && isset($_GET['id'])) { if($_GET['act'] == "eat") { try and break it down a bit first and see what happens. ACE Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 29, 2008 Author Share Posted June 29, 2008 <?php if (isset($_GET['pet']) && isset($_GET['id'])) { if($_GET['act'] == "eat") { try and break it down a bit first and see what happens. ACE Thanks for the quick response. I did try it with just the isset's but it still came up false. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 29, 2008 Share Posted June 29, 2008 <?php if($_GET['act'] == "eat") { if (isset($_GET['pet']) && isset($_GET['id'])) { I assume act is the page they are on, or what there action is. So check for the action(act) first before seeing if whatever has to be done in the 'act' is set. see if that works. Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 29, 2008 Author Share Posted June 29, 2008 <?php if($_GET['act'] == "eat") { if (isset($_GET['pet']) && isset($_GET['id'])) { I assume act is the page they are on, or what there action is. So check for the action(act) first before seeing if whatever has to be done in the 'act' is set. see if that works. Yup, the act is working good. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 29, 2008 Share Posted June 29, 2008 Put <?php echo '<pre>' . print_r($_GET,true) . '</pre>'; ?> Right before the "if" statement to show what's in the $_GET array at that time. Ken Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 29, 2008 Author Share Posted June 29, 2008 Put <?php echo '<pre>' . print_r($_GET,true) . '</pre>'; ?> Right before the "if" statement to show what's in the $_GET array at that time. Ken It's only showing the action, not the issets Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 29, 2008 Author Share Posted June 29, 2008 Do I have the ()'s wrong or is it the 2 issets or ... this is kind of important. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 29, 2008 Share Posted June 29, 2008 Is the code block that creates the links and the code block that has the problem in the same script or in different scripts? If it's it the same script, you have to remember that the values in the $_GET array won't be set until you click the link and reload the script. Ken Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 29, 2008 Author Share Posted June 29, 2008 Is the code block that creates the links and the code block that has the problem in the same script or in different scripts? If it's it the same script, you have to remember that the values in the $_GET array won't be set until you click the link and reload the script. Ken Well I checked and they're all set correctly, it just isn't testing the "if" statement. I've never had this problem until I put 2 issets into one line so that's why I figured that maybe the parentheses were wrong ... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 29, 2008 Share Posted June 29, 2008 I created a test script <?php echo '<pre>' . print_r($_GET,true) . '</pre>'; $pets = array('id' => 235, 'name' => 'pets name'); $items_id = 1234; echo "<br /><br /><a href='?act=eat&pet=".$pets['id']."&id=".$items_id."'>Feed to ".$pets['name']."</a>"; if ($_GET['act'] == "eat" && (isset($_GET['pet'])) && (isset($_GET['id']))) { echo '<br />Ok'; } ?> and it works fine, so your problem is somewhere else you haven't shown us. Ken Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 Still can't figure it out. Here's the entire code: <?php if (isset($_GET['id'])) { $items_id = $_GET['id']; $user_id = $_COOKIE['user_id']; $select = mysql_query("SELECT * FROM `inventory` WHERE id='$items_id'"); $row = mysql_fetch_array($select); $item_id = $row['item_id']; $item_info = mysql_query("SELECT * FROM `items` WHERE id='$item_id'"); $item = mysql_fetch_array($item_info); if ($user_id == $row['user_id']) { echo "<h2>".$item['name']."</h2>"; echo "<img src='../images/items/".strtolower($item['name']).".gif'><br />".$item['name']."<br /><b>Rarity:</b> ".$item['rarity']."<br />".$item['description'].""; if ($item['feed'] == 1) { $user_pet = mysql_query("SELECT * FROM `user_pets` WHERE owner_id='$user_id'"); while ($pets = mysql_fetch_array($user_pet)) { echo "<br /><br /><a href='/place/item.php?act=eat&pet=".$pets['id']."&id=".$row['id']."'>Feed to ".$pets['name']."</a>"; } // End while } // End if if ($item['donate'] == 1) { echo "<br /><a href='/place/item.php?act=donate&id=".$items_id."'>Donate to the Donation Shack</a>"; } // End if if ($item['auction'] == 1) { echo "<br />Put ".$item['name']." up for auction"; } // End if if ($item['sell'] == 1) { echo "<br />Put ".$item['name']." in your shop"; } // End if if ($item['give'] == 1) { echo "<br />Give ".$item['name']." to a user"; } // End if if ($item['wear'] == 1) { echo "<br />Put ".$item['name']." into your closet"; } // End if } else { echo "<b>Error:</b> That item cannot be found!"; } } elseif ($_GET['act'] == "eat") { if ((isset($_GET['pet'])) && (isset($_GET['id']))) { $pet = $_GET['pet']; $item_id = $_GET['id']; $select = mysql_query("SELECT * FROM `user_pets` WHERE id='$pet'"); $row = mysql_fetch_array($select); echo "Act is working"; /* if ($row['hunger'] == 100) { echo "".$row['name']." is already full!"; } else { $hunger = $row['hunger']+20; if ($hunger > 100) { $new_hunger = 100; } else { $new_hunger = $hunger; } // End if $update_hunger = mysql_query("UPDATE `user_pets` SET hunger='$new_hunger' WHERE id='$pet'"); $delete_item = mysql_query("DELETE FROM `inventory` WHERE id='$item_id'"); header('Location: item.php?act=fed&pet='.$pet.''); } // End if */ } } elseif ($_GET['act'] == "fed" && (isset($_GET['pet']))) { $pet = $_GET['pet']; $select = mysql_query("SELECT * FROM `user_pets` WHERE id='$pet'"); $row = mysql_fetch_array($select); echo "".$row['name']." is now ".$row['hunger']."% full."; } else { header('Location: /404.php'); } ?> Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 Can anyone still help me, I need this done? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 turn error reporting on ini_set('error_reporting',E_ALL); Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 turn error reporting on ini_set('error_reporting',E_ALL); It still doesn't change anything. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 Fix: if (isset($_GET['pet'])||isset($_GET['id'])) { Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 Fix: if (isset($_GET['pet'])||isset($_GET['id'])) { 1. That's an error 2. That means OR, not AND. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 yes it does mean OR but it shouldnt error. it should work fine Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 yes it does mean OR but it shouldnt error. it should work fine I don't think you get it ... I NEED AND or else it can be easily manipulated And it doesn't work. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 nevermind you need && or it returns false Fixed again: if (isset($_GET['pet']) && isset($_GET['id'])) { Quote Link to comment Share on other sites More sharing options...
Juan Dela Cruz Posted June 30, 2008 Share Posted June 30, 2008 you have main if and else's that wrap these whole code on your first condtion you ask if $_GET[id ] is set..might work but on the elseif you use the get id? thats means id is set so theres no reason that the condition will go on your second condition hope that helps i f (isset($_GET['id'])) { <----------------------here id should be set } } elseif ($_GET['act'] == "eat") { if ((isset($_GET['pet'])) && (isset($_GET['id']))) { $pet = $_GET['pet']; $item_id = $_GET['id'];<-----------------------------------------------------here id is set edited to be clear Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 your structure is flawed you cannot have an else before an else if. structure hiararchy: if(){} else if(){} else(){} Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 your structure is flawed you cannot have an else before an else if. structure hiarchy: if(){} else if(){} else(){} Who are you talking to? No one is doing that. Sorry but you're 0 for 5. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 scuse me there is no room for being rude in this forum. it will just be locked. Also you will get no help with that sort of behavior. goodluck finding some. Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted June 30, 2008 Author Share Posted June 30, 2008 you have main if and else's that wrap these whole code on your first condtion you ask if $_GET[id ] is set..might work but on the elseif you use the get id? thats means id is set so theres no reason that the condition will go on your second condition hope that helps i f (isset($_GET['id'])) { <----------------------here id should be set } } elseif ($_GET['act'] == "eat") { if ((isset($_GET['pet'])) && (isset($_GET['id']))) { $pet = $_GET['pet']; $item_id = $_GET['id'];<-----------------------------------------------------here id is set edited to be clear You're right, the id is already being set before! Thank you! Quote Link to comment 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.