cdoyle Posted November 27, 2008 Share Posted November 27, 2008 Hi, I'm trying to develop a page, that allows players to send cash to each other. How I want it to work is like this, The page first opens with a form, that allows users to enter the ID of the player and the amount. It then sends goes to the "cost" case and displays the fee, it will then take them to the "send" where it updates the tables etc. here is my question, when the page first opens. The first form, does it belong in the default case? Or should it be outside the switch? I'm thinking outside, but I couldn't get it to work. If it does indeed need to outside the switch, what should I set my default too? Then the next issue I'm having is, on the first form if I set the action to POST, then my switch needs to be $_GET or if I set my form action to $_GET my switch needs to $_POST. So I'm doing something wrong, and hoping that it just has to do with my first question.. Here is my code. switch ($_GET['act']) { case "cost"; if(isset($_POST['sendto2']) && ($_POST['amount']) ) { If(is_numeric($_POST['sendto2'])&& ($_POST['amount']) ) { $sendtoplayer=stripslashes($_POST['sendto2']); $wireamount=stripslashes($_POST['amount']); $sendto = $db->execute("SELECT `id`, `username` from `players` WHERE `id`=?", array ($sendtoplayer)); $sendto1 = $sendto->fetchrow(); $playerid=$sendto1['id']; $getfee = $wireamount*.05; if ($sendto->recordcount() == 0) { echo "Stop wasting our time, and enter a valid person"; } else { echo "You would like to send\n" . $wireamount . "\nto\n" . $sendto1['username'] . "?<br>"; echo "Our fee for this transaction will be\n" . $getfee; echo "<form method=\"post\" action=\"U-Send.php?act=send\">"; echo "<input type=\"hidden\" name=\"sentto\" value=\"$playerid\">"; echo "<input type=\"hidden\" name=\"amountsent\" value=\"$wireamount\">"; echo "<input type=\"submit\" name=\"yes\" value=\"Send Cash Now!!!\">"; } } else { echo "Please enter a valid amount"; } } break; case "send"; if(isset($_POST['sentto']) && ($_POST['amountsent']) ) { If(is_numeric($_POST['sentto'])&& ($_POST['amountsent']) ) { $wireamount1=stripslashes($_POST['amountsent']); $sendtoplayer=stripslashes($_POST['sentto']); $getfee = $wireamount1*.05; $sendto = $db->execute("SELECT `id`, `username` from `players` WHERE `id`=?", array ($sendtoplayer)); $sendto1 = $sendto->fetchrow(); $gettotal = $wireamount1+$getfee; if ($sendto->recordcount() == 0) { echo "Not a valid user"; } elseif ($player->gold < $getfee) { echo "You don't have enough funds to cover this transaction"; } elseif ($player->id < $sendtoplayer) { echo "Please don't try and send cash to yourself, you just look foolish"; } else { $updatereceiver = $db->execute("Update `players` set `gold`=`gold`+? WHERE `id`=?", array($wireamount1,$sendtoplayer )); $updatesender = $db->execute("Update `players` set `gold`=`gold`-? Where `id`=?", array($gettotal, $player->id)); $updatelog = $db->execute("Insert INTO `money_transaction` (`sender_id`,`receiver_id`, `amount`, `date_sent`) VALUES ($player->id, $sendtoplayer,$wireamount1, $currentime)"); echo "You just sent\n" . $sendto1['username'] . "\n$\n" . $wireamount1; } } } break; default: echo "<h3>Welcome to Quick Send</h3><p>"; echo "Got a friend with a little bit of a money problem? Need to get them some cash quick before someone busts their legs?\n"; echo "Then you've come to the right place, we can wire money to anyone and the best part is our fees are low!!<p>"; echo "We only charge a 5% fee on all transactions"; echo "<form method=\"POST\" action=\"U-Send.php?act=cost\">"; echo "<strong>Send to player ID:</strong><input type=\"text\" name=\"sendto2\" size=\"5\"><br>"; echo "<strong>Amount to Send</strong><input type=\"text\" name=\"amount\" size=\"5\"><br>"; echo "<input type=\"submit\" name=\"yes\" value=\"Send Cash\">"; echo "</form>"; } include("templates/private_footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/ Share on other sites More sharing options...
rhodesa Posted November 27, 2008 Share Posted November 27, 2008 It should be in your default. And I don't understand your GET/POST question... Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700562 Share on other sites More sharing options...
kenrbnsn Posted November 27, 2008 Share Posted November 27, 2008 You end a "case" statement with a colon ":", not a semi-colon ";". You are using a semi-colon. Ken Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700682 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 You end a "case" statement with a colon ":", not a semi-colon ";". You are using a semi-colon. Ken hehe...yes, that too Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700706 Share on other sites More sharing options...
cdoyle Posted November 28, 2008 Author Share Posted November 28, 2008 darn it, I didn't even notice I did that. Thanks for catching pointing out the semi colon. My question with the post/get. Since my form action is POST, what should my SWITCH be? Should it be $Get or $Post? It seems to only work when it's the opposite of what my form is? Is that how it's suppose to work? Also, I never seem to get the is_numeric isset thing right. Am I coding it right in my example? If not, how should it look? I don't think it's right since it let me put text into the field, and it executes the 'cost' case. Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700727 Share on other sites More sharing options...
cdoyle Posted November 28, 2008 Author Share Posted November 28, 2008 does this look correct? It seems to work, it's stopping me from entering text, just want to make sure it's right case "cost": if(isset($_POST['sendto2'])) { if(isset($_POST['amount']) ) { If(is_numeric($_POST['sendto2'])) { If(is_numeric($_POST['amount'])) { $sendtoplayer=stripslashes($_POST['sendto2']); $wireamount=stripslashes($_POST['amount']); $sendto = $db->execute("SELECT `id`, `username` from `players` WHERE `id`=?", array ($sendtoplayer)); $sendto1 = $sendto->fetchrow(); $playerid=$sendto1['id']; $getfee = $wireamount*.05; if ($sendto->recordcount() == 0) { echo "Stop wasting our time, and enter a valid person"; } elseif ($_POST['amount'] <= 0) { echo "You can't send negative cash moron."; } else { echo "You would like to send\n" . $wireamount . "\nto\n" . $sendto1['username'] . "?<br>"; echo "Our fee for this transaction will be\n" . $getfee; echo "<form method=\"post\" action=\"U-Send.php?act=send\">"; echo "<input type=\"hidden\" name=\"sentto\" value=\"$playerid\">"; echo "<input type=\"hidden\" name=\"amountsent\" value=\"$wireamount\">"; echo "<input type=\"submit\" name=\"yes\" value=\"Send Cash Now!!!\">"; } } Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700731 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 your switch should be GET because your 'act' variable is in the URL: echo "<form method=\"post\" action=\"U-Send.php?act=send\">"; the elements in the form will follow the form method. but if you have variables in the action, those will always be get. if you put a hidden input element in the form, you would use POST, but the way you have it is fine. Link to comment https://forums.phpfreaks.com/topic/134530-help-with-switch-this-has-been-driving-me-nuts/#findComment-700751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.