3raser Posted March 14, 2011 Share Posted March 14, 2011 Heres my code: <?php include_once("db_connect.php"); if(isset($_COOKIE['user'])) { //get who to steal from $from = mysql_real_escape_string($_GET['from']); //check if they selected someone if(!$from) { echo "You haven't selected a user to steal from!"; } else { if(!$_POST['amount']) { echo "Amount to steal from ". $from .": <form action='steal.php' method='POST'> <input type='text' name='amount'><input type='submit' value='Steal'></form>"; } else { //grab the other users money $grab_other = mysql_query("SELECT money FROM users WHERE username = '$from'"); //extract $extract = mysql_fetch_assoc($grab_other); //check if the user is valid if(mysql_num_rows($grab_other) == 0) { } elseif($extract['money'] == $_POST['amount']) { $one = rand(1, $_POST['amount']); $two = rand(1, $_POST['amount']); //if they successfully stole if($one == $two) { echo "You've successfully stole from ". $from ."! $". $_POST['amount'] ." has been added to your account!"; } } else { echo "They don't have enough money!"; } } } } else { echo "You must be logged in before you can do this! <a href='index.php'>Home</a>"; } ?> $from (which is a GET) is who the user wish to steal from. How do I carry that over? If they go here: http://composedscripts.zxq.net/money_game/steal.php?from=Justin - And they enter in an amount, it will forget $from and say they haven't entered in a user to steal from. How do I stop this from happening? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 14, 2011 Share Posted March 14, 2011 If they go here: http://composedscripts.zxq.net/money_game/steal.php?from=Justin - And they enter in an amount, it will forget $from and say they haven't entered in a user to steal from. How do I stop this from happening? You mean, if they go to the link with from=Justin they are presented with a page to enter a value THEN when the user submits the page the processing page does not have access to the previous "%from" value, correct? On the page steal.php where you are creating a form for the user to enter an amount, use the $from value to populate a hidden field in the form. Then the page that processes the page will have the value passed in the POST data. Quote Link to comment Share on other sites More sharing options...
3raser Posted March 14, 2011 Author Share Posted March 14, 2011 If they go here: http://composedscripts.zxq.net/money_game/steal.php?from=Justin - And they enter in an amount, it will forget $from and say they haven't entered in a user to steal from. How do I stop this from happening? You mean, if they go to the link with from=Justin they are presented with a page to enter a value THEN when the user submits the page the processing page does not have access to the previous "%from" value, correct? On the page steal.php where you are creating a form for the user to enter an amount, use the $from value to populate a hidden field in the form. Then the page that processes the page will have the value passed in the POST data. Thanks! But I could've swore Thorpe said their was another way. He tends to smash the information in your brain. D: Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 14, 2011 Share Posted March 14, 2011 If they go here: http://composedscripts.zxq.net/money_game/steal.php?from=Justin - And they enter in an amount, it will forget $from and say they haven't entered in a user to steal from. How do I stop this from happening? You mean, if they go to the link with from=Justin they are presented with a page to enter a value THEN when the user submits the page the processing page does not have access to the previous "%from" value, correct? On the page steal.php where you are creating a form for the user to enter an amount, use the $from value to populate a hidden field in the form. Then the page that processes the page will have the value passed in the POST data. Thanks! But I could've swore Thorpe said their was another way. He tends to smash the information in your brain. D: Yes, there are many way to accomplish what you are asking. If Thorpe suggested something different I will assume he had a good reason for doing so. You may have provided him with slightly different information that led him to provide a solution that would be better in the context that he understood it. Quote Link to comment Share on other sites More sharing options...
.josh Posted March 15, 2011 Share Posted March 15, 2011 You can... - Put it in a hidden field as mjdamato suggested. This will make it available as either a GET or POST variable, depending on what method you use for your form. - Append it to the form action's URL. This will make it available as a GET variable. - Start a session variable, holding that information. This will make it available as a SESSION variable, without depending on it being passed again from the client. In and of themselves, none of these are particularly the "best" way to do it, though if you are following some kind of convention in your coding, you might wanna stick with one way over mixing and matching. 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.