Jump to content


Photo

What's wrong?


  • Please log in to reply
36 replies to this topic

#1 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 14 September 2006 - 09:45 PM

I'm making a script where when you click on and item it goes to the next screen and you click on a link which takes you to a new screen then you click on the pet that you want to use the item on, which produces a popup window that runs a few scripts (decrease the hunger, update last time fed, and delete the item) and displays a confirmation message. Somehow the data's not being sent from page to page somewhere. The message should read 'you have used ____ on ____!' but it says 'You have used on ___!'. Can someone help me? Just let me know which codes you need to see.
Schroedinger's Cat walks into a bar.
And doesn't.

#2 ultrus

ultrus
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 14 September 2006 - 11:45 PM

I had a project at one time that required passing a variable from page to page to page. At first, my variable from the first page would be visible on the second page, but dissapear on the page after that. To fix it, I did something like this:

page 1:
<form action="page2.php" method="post" name="form1">
<input name="animal" type="text">
<input name="submit" type="submit" value="submit">
</form>

page2:
<form action="page3.php" method="post" name="form1">
<input name="animal" type="hidden" value="<?php echo $_POST['animal'] ?>">
<input name="animal" type="text">
<input name="submit" type="submit" value="submit">
</form>

page3:
Your animal is: <?php echo $_POST['animal'] ?>

Is this what you were looking for? Hope this helps!
Twitter | Blog | Worlds to explore. Worlds to create.

#3 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 15 September 2006 - 12:11 AM

Actualy i think that it's sending the variable right, it's just not working for some reason. This is the code for the final page that does the stuff and displays a confirmation messages:

<?php

session_start();
$session = session_id();

include ("../htm/siteinfo.htm"); 
include ("dbinfo.php");

 $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";

   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$hunger = $query_data['hunger'];
	$monopetName = $query_data['monopetName'];
	
	 $SQL = "SELECT * FROM myitemschibi WHERE itemID = '$itemID'";

   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$food = $query_data['food'];
	$itemName = $query_data['itemName'];
	
	$fedtime = strtotime("today");
	$itemID = $_POST['itemID'];
	$monopetID = $_POST['monopetID'];


if ($food == "Food");
	{
		$hunger--;
	}
	
if ($food == "Food");
	{
		$SQL = "DELETE from myitemschibi WHERE itemID = $itemID";
	}
	
if ($food == "Food");
	{
		$SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE petID = $petID";
	}
	
?>

You have used <? print"$itemName" ?> on <? print"$monopetName" ?>!

Schroedinger's Cat walks into a bar.
And doesn't.

#4 ultrus

ultrus
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 15 September 2006 - 02:08 PM

Hmmm. I date to admit it, but I'm stumped. :P
Twitter | Blog | Worlds to explore. Worlds to create.

#5 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 15 September 2006 - 08:41 PM

I can't figure it out and I need it working by today ???. I just dont have a clue.
Schroedinger's Cat walks into a bar.
And doesn't.

#6 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 04:41 PM

I've got it to send the variable but in the last page none of the querys and stuff are working.

<?php

session_start();
$session = session_id();

include ("../htm/siteinfo.htm"); 
include ("dbinfo.php");
include ("config.php");

 $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";

   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$hunger = $query_data['hunger'];
	$monopetName = $query_data['monopetName'];
	
	 $SQL = "SELECT * FROM myitemschibi WHERE itemID = '$itemID'";

   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$food = $query_data['food'];
	$itemName = $query_data['itemName'];
	
	$fedtime = strtotime("today");
	$itemID = $_POST['itemID'];
	$monopetID = $_POST['monopetID'];


if ($food == "Food");
	{
		$hunger--;
	}
	
if ($food == "Food");
	{
		$SQL = "DELETE from myitemschibi WHERE itemID = $itemID";
	}
	
if ($food == "Food");
	{
		$SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE petID = $petID";
	}
	
?>

You have used <? print"$itemName" ?> on <? print"$monopetName" ?>!

Schroedinger's Cat walks into a bar.
And doesn't.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 04:59 PM

Where does that script get the values for $monopetID and $itemID?  If they're session values, you need to retrieve them ...



Legend has it that reading the manual never killed anyone.
My site

#8 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:02 PM

I have that...

$itemID = $_POST['itemID'];
$monopetID = $_POST['monopetID'];
Schroedinger's Cat walks into a bar.
And doesn't.

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:03 PM

I have that...

$itemID = $_POST['itemID'];
$monopetID = $_POST['monopetID'];


No. You don't have them for the queries ... look at this:

<?php

session_start();
$session = session_id();

include ("../htm/siteinfo.htm"); 
include ("dbinfo.php");
include ("config.php");

 $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";

Legend has it that reading the manual never killed anyone.
My site

#10 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:05 PM

I moved them between the includes and the queries, it still doesn't work.
Schroedinger's Cat walks into a bar.
And doesn't.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:09 PM

#1 - add error trapping and information display to the code while you're debugging. Change each of these:

$result = mysql_query($SQL,$connection);

to this:

echo "<br/>". $SQL. "<br/>";// show the actual query string
$result = mysql_query($SQL,$connection) or die("Error: ". mysql_error(). " with query ". $SQL);// show error information if one occurs

#2 - if the problem persists, then post the current version of the code so that future posters here can see exactly what you're working with.

Edit: if you're passing the information through a link, then the passed data are in the $_GET array, not $_POST.
Legend has it that reading the manual never killed anyone.
My site

#12 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:12 PM

now

SELECT * FROM chibifriendspets WHERE monopetID = '26'

SELECT * FROM myitemschibi WHERE itemID = '58'

Shows up in the page.

I dont know what's not working but all the things in the if parts that should be executing are not. My current code is:

<?php

session_start();
$session = session_id();

include ("../htm/siteinfo.htm"); 
include ("dbinfo.php");
include ("config.php");

	$itemID = $_POST['itemID'];
	$monopetID = $_POST['monopetID'];

 $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";

echo "<br/>". $SQL. "<br/>";// show the actual query string
$result = mysql_query($SQL,$connection) or die("Error: ". mysql_error(). " with query ". $SQL);// show error information if one occurs
	$query_data = mysql_fetch_array($result);
	$hunger = $query_data['hunger'];
	$monopetName = $query_data['monopetName'];
	
	 $SQL = "SELECT * FROM myitemschibi WHERE itemID = '$itemID'";

echo "<br/>". $SQL. "<br/>";// show the actual query string
$result = mysql_query($SQL,$connection) or die("Error: ". mysql_error(). " with query ". $SQL);// show error information if one occurs
	$query_data = mysql_fetch_array($result);
	$food = $query_data['food'];
	$itemName = $query_data['itemName'];
	
	$fedtime = strtotime("today");



if ($food == "Food");
	{
		$hunger--;
	}
	
if ($food == "Food");
	{
		$SQL = "DELETE from myitemschibi WHERE itemID = $itemID";
	}
	
if ($food == "Food");
	{
		$SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE petID = $petID";
	}
	
?>

You have used <? print"$itemName" ?> on <? print"$monopetName" ?>!

Schroedinger's Cat walks into a bar.
And doesn't.

#13 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 16 September 2006 - 05:15 PM

Basically, you would like your "members" to click one an "item"
then it will confirm to what they have purchased, then
auto-redirect to another page?

OR they click [continue] and it takes them to the next page?

& whats the problem?

#14 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:17 PM

I'm not sure why you need to have three conditional statements all separated the way you have them, but the reason that 'nothing' happens is that all you do in that code is define a query string and never execute the query.

And in the query string ... WHERE petID = $petID ... $petID is never defined elsewhere in your code.
Legend has it that reading the manual never killed anyone.
My site

#15 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:19 PM

It's a virtual pet gamin site thing. I'm trying to have the uers select an item from their inventory, which takes them to a page saying which pet would you like to use it on, which opens a new window that executes a bunch of things (like decreasing the pet's hunger and deleting the item) and gives a confirmation message.

It displays the message, which means it's recieving the variables, but the pet's hunger stays the same and it doesnt delete the item.
Schroedinger's Cat walks into a bar.
And doesn't.

#16 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:20 PM

I'm not sure why you need to have three conditional statements all separated the way you have them, but the reason that 'nothing' happens is that all you do in that code is define a query string and never execute the query.


How do I execute it?
Schroedinger's Cat walks into a bar.
And doesn't.

#17 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:22 PM

How do I execute it?

Remember this?

$result = mysql_query($SQL,$connection) or die("Error: ". mysql_error(). " with query ". $SQL);// show error information if one occurs

Legend has it that reading the manual never killed anyone.
My site

#18 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:23 PM

I put that in the queries and got this:

Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE petID =' at line 1 with query UPDATE chibifriendspets SET lastDatefed = 1158427658, WHERE petID =
Schroedinger's Cat walks into a bar.
And doesn't.

#19 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:30 PM

Read post #13. I warned you that $petID was never acquired by your code.
Legend has it that reading the manual never killed anyone.
My site

#20 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 05:36 PM

Ok. That was suppossed to be monopetID and I changed it. Now I get this:

Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE monopetID = 26' at line 1 with query UPDATE chibifriendspets SET lastDatefed = 1158428142, WHERE monopetID = 26

It also isn't decreasing the hunger.
Schroedinger's Cat walks into a bar.
And doesn't.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users