thetick Posted February 18, 2010 Share Posted February 18, 2010 I made a small script wich exchanges points in my website: <?php session_start(); include_once"config.php"; $username = $_SESSION['username']; if(isset($_POST['exchange'])){ $spoints = $_POST['spoints']; switch ($spoints) { case 200: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output = "You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+1 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-200 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 1 more referral."; } break; case 400: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output = "You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+2 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-400 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 2 more referrals."; } break; case 600: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+3 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-600 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 3 more referrals."; } break; case 800: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+4 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-800 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 4 more referrals."; } break; case 1000: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+5 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-1000 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 5 more referrals."; } break; case 1200: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+6 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-1200 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 6 more referrals."; } break; case 1400: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+7 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-1400 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 7 more referrals."; } break; case 1600: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+8 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-1600 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 8 more referrals."; } break; case 1800: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+9 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-1800 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 9 more referrals."; } break; case 2000: $check_if_have_points = mysql_query("SELECT points FROM members WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($check_if_have_points); if($row['points']< 200){ $error_output="You do not have enough points"; } else { $updateuserofferstatus = mysql_query("UPDATE `members` SET `offer_status` = offer_status+10 WHERE `username`= '$username'") or die(mysql_error()); $updateuserpoints = mysql_query("UPDATE members SET points=points-2000 WHERE username='$username'"); $error_output = "Congratulations ".$username.". You now have 10 more referrals."; } break; } } ?> <div style="width:60%;vertical-align:top;text-align:left;overflow:visible;" id="exchange"> <form action="" method="post"> <fieldset style="border:none;"> <p> <label for="username" style="font-weight:normal;width:11%;float:left;display:block;">Points:</label> <input type="text" name="spoints" class="item" value="" /> <span class="style27">(how many points to exchange)</span></p> <p><input type="submit" name="exchange" value="Exchange" id="exchange" style="float:left;border:1px solid #999;background:#E4E4E4;margin-top:5px;" /></p> </fieldset> </form> <br><font color="red"><?php echo $error_output?></font></div> It works great ... but the problem is after I enter the points and they are exchanged, if i refresh the page they get exchanged again. How can I resolv this. I tried addind some meta refresh but it doesn't resolve the problem. Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/ Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 Not sure this will solve the proble but u can try: if(isset($_POST['exchange'])) { //switch block unset($_POST['exchange']); } Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014282 Share on other sites More sharing options...
thetick Posted February 18, 2010 Author Share Posted February 18, 2010 nope not working .... still the same. Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014351 Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 could u explane what u trying todo? I see u are spending some point then u increase referal count. But it looks like u just have bunch of case: statements instead one with some nice formula. If u would explane your task here and the points/referal sums I think it would be possible write more effetient code Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014363 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 The way i think can fix it, after success try redirect user even to same page. header('Location: www.mysite.com/page.php'); exit(); so that your post data getting lost. Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014376 Share on other sites More sharing options...
thetick Posted February 18, 2010 Author Share Posted February 18, 2010 ok so what this script does is this: it allows my users to exchange points to refferal points. the points would be the $spoints = $_POST['spoints']; and for every 200 points exchanged it ads 1 point to the offer_status table LeadingWebDev: I would like a way to do this and prompt a message to the user so it doesn't look like it's doing nothing Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014534 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 did u tried header(); ? or even redirect to thank page? Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014537 Share on other sites More sharing options...
thetick Posted February 18, 2010 Author Share Posted February 18, 2010 ahaaaaa ... wait i figured out a way ... after the script is executed I redirect to a page where I gives the user the message and then redirect back to the page with the script. thx all for the ideas. Link to comment https://forums.phpfreaks.com/topic/192505-problems-with-script/#findComment-1014558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.