Jump to content

[SOLVED] GET problem


ryeman98

Recommended Posts

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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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');
} ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.