Jump to content

Archived

This topic is now archived and is closed to further replies.

Pi_Mastuh

What's wrong?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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:
[code]<form action="page2.php" method="post" name="form1">
<input name="animal" type="text">
<input name="submit" type="submit" value="submit">
</form>[/code]

page2:
[code]<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>[/code]

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

Is this what you were looking for? Hope this helps!

Share this post


Link to post
Share on other sites
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:

[code]<?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" ?>![/code]

Share this post


Link to post
Share on other sites
I've got it to send the variable but in the last page none of the querys and stuff are working.

[code]<?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" ?>![/code]

Share this post


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


Share this post


Link to post
Share on other sites
[quote author=Pi_Mastuh link=topic=108091.msg435598#msg435598 date=1158426124]
I have that...

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

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

[code]<?php

session_start();
$session = session_id();

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

$SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";[/code]

Share this post


Link to post
Share on other sites
#1 - add error trapping and information display to the code while you're debugging. Change each of these:

[code]$result = mysql_query($SQL,$connection);[/code]

to this:

[code]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[/code]

#2 - if the problem persists, then post the [i]current[/i] 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.

Share this post


Link to post
Share on other sites
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:

[code]<?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" ?>![/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=108091.msg435610#msg435610 date=1158427076]
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.
[/quote]

How do I execute it?

Share this post


Link to post
Share on other sites
[quote author=Pi_Mastuh link=topic=108091.msg435613#msg435613 date=1158427210]
How do I execute it?
[/quote]
Remember this?

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

Share this post


Link to post
Share on other sites
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 =

Share this post


Link to post
Share on other sites
Read post #13. I warned you that $petID was never acquired by your code.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
$SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE ...

Remove the comma after $fedtime

Share this post


Link to post
Share on other sites
try this...
[code=php:0]<?php

session_start();
$session = session_id();

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


$SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '".$_POST['monopetID']."'";

$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result);
$hunger = $query_data['hunger'];
$monopetName = $query_data['monopetName'];

$SQLB = "SELECT * FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'";

$result2 = mysql_query($SQLB,$connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result2);
$food = $query_data['food'];
$itemName = $query_data['itemName'];

$fedtime = strtotime("today");


if ($food == "Food")
{
$hunger--;
mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");
mysql_query("UPDATE chibifriendspets SET lastDatefed = '$fedtime' WHERE petID = '".$_POST['monopetID']."'");

echo "<p>Yopu have used <b>".$itemName."</b> on <b>".$monopetName."</b>!</p>";
}

?>[/code]

Share this post


Link to post
Share on other sites
It works, but it still doesn't decrease the hunger. Do I need to do more to save the decreased hunger in the database?

Share this post


Link to post
Share on other sites
Yes.  In some query, you'll have to UPDATE the value of the hunger field.

Share this post


Link to post
Share on other sites

×

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.