Pi_Mastuh Posted September 14, 2006 Share Posted September 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
ultrus Posted September 14, 2006 Share Posted September 14, 2006 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! Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 15, 2006 Author Share Posted September 15, 2006 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]<?phpsession_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] Quote Link to comment Share on other sites More sharing options...
ultrus Posted September 15, 2006 Share Posted September 15, 2006 Hmmm. I date to admit it, but I'm stumped. :P Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 15, 2006 Author Share Posted September 15, 2006 I can't figure it out and I need it working by today ???. I just dont have a clue. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 I've got it to send the variable but in the last page none of the querys and stuff are working.[code]<?phpsession_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] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 Where does that script get the values for $monopetID and $itemID? If they're session values, you need to retrieve them ... Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 I have that... $itemID = $_POST['itemID']; $monopetID = $_POST['monopetID']; Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 [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]<?phpsession_start();$session = session_id();include ("../htm/siteinfo.htm"); include ("dbinfo.php");include ("config.php"); $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";[/code] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 I moved them between the includes and the queries, it still doesn't work. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 #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. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 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]<?phpsession_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] Quote Link to comment Share on other sites More sharing options...
xyn Posted September 16, 2006 Share Posted September 16, 2006 Basically, you would like your "members" to click one an "item"then it will confirm to what they have purchased, thenauto-redirect to another page?OR they click [continue] and it takes them to the next page?& whats the problem? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 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. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 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. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 [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? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 [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] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 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 = Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 Read post #13. I warned you that $petID was never acquired by your code. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 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 = 26It also isn't decreasing the hunger. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 $SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE ...Remove the comma after $fedtime Quote Link to comment Share on other sites More sharing options...
xyn Posted September 16, 2006 Share Posted September 16, 2006 try this...[code=php:0]<?phpsession_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] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 It works, but it still doesn't decrease the hunger. Do I need to do more to save the decreased hunger in the database? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 Yes. In some query, you'll have to UPDATE the value of the hunger field. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 Ok. 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.