Send Points


Mentioned by -=InSaNe=- made by SkillMaster

Save as send_points.php
PHP Code
  1. <?php
  2. session_start();
  3. include "config.php";
  4. if($logged[username])
  5. {
  6. switch($_GET[page])
  7. {
  8. default:
  9. echo ("
  10. You have <b>$logged[points]</b> points in hand to send.<br>
  11. <form method='post' action='?page=send'>
  12. <select name='username'>");
  13. $fetch = mysql_query("SELECT * FROM `members`");
  14. while ($user = mysql_fetch_array($fetch))
  15. {
  16. echo ("<option value='$user[username]'>$user[username]</option>");
  17. }
  18. echo ("
  19. </select><br>
  20. <input type='text' name='points' size='20'>
  21. <input type='submit' name='submit' value='Send'>");
  22. break;
  23.  
  24. case 'send':
  25. $username = strip_tags(htmlspecialchars($_POST[username]));
  26. $points = strip_tags(htmlspecialchars($_POST[points]));
  27. if ($logged[points] < $points)
  28. {
  29. echo ("You don't have that many points. <a href='send_points.php'>Back</a>");
  30. }
  31. elseif ($points == NULL)
  32. {
  33. echo ("Please enter a value of points. <a href='send_points.php'>Back</a>");
  34. }
  35. else
  36. {
  37. $fetch = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");
  38. $user = mysql_fetch_array($fetch);
  39.  
  40. $points1 = $logged[points]-$points;
  41. $points2 = $user[points]+$points;
  42.  
  43. $update1 = mysql_query("UPDATE `members` SET `points` = '$points1' WHERE `username` = '$logged[username]'");
  44. $update2 = mysql_query("UPDATE `members` SET `points` = '$points2' WHERE `username` = '$username'");
  45. echo ("You have sent $points to $username. <a href='send_points.php'>Back</a>");
  46. }
  47. break;
  48. }
  49. }
  50. ?>


PHP Code
  1. $fetch = mysql_query("SELECT * FROM `members`");
  2. while ($user = mysql_fetch_array($fetch))
  3. {
  4. echo ("<option value='$user[username]'>$user[username]</option>");
  5. }

Displays all of our users.

PHP Code
  1. <form method='post' action='?page=send'>
  2. <select name='username'>");
  3. $fetch = mysql_query("SELECT * FROM `members`");
  4. while ($user = mysql_fetch_array($fetch))
  5. {
  6. echo ("<option value='$user[username]'>$user[username]</option>");
  7. }
  8. echo ("
  9. </select><br>
  10. <input type='text' name='points' size='20'>
  11. <input type='submit' name='submit' value='Send'>");

Our form to define our variables.

PHP Code
  1. if ($logged[points] < $points)
  2. {
  3. echo ("You don't have that many points. <a href='send_points.php'>Back</a>");
  4. }

if the users points is less than the points they are trying to send they get an error messge

PHP Code
  1. $points1 = $logged[points]-$points;
  2. $points2 = $user[points]+$points;
  3.  
  4. $update1 = mysql_query("UPDATE `members` SET `points` = '$points1' WHERE `username` = '$logged[username]'");
  5. $update2 = mysql_query("UPDATE `members` SET `points` = '$points2' WHERE `username` = '$username'");
  6. echo ("You have sent $points to $username. <a href='send_points.php'>Back</a>");

Does out math and then updates the database gives us a success message.

That it.
Live earth on soon.
SkillMaster's Avatar
Views:
2,516
Rating:
Posted on Tuesday 8th April 2008 at 06:44 PM
Dalez
Dalez's Avatar
You can send points to yourself, and they keep adding up!

How do i fix this?
Posted on Tuesday 8th April 2008 at 02:20 AM
UrbanTwitch
UrbanTwitch's Avatar
How do you get points?!
Posted on Sunday 18th November 2007 at 08:09 PM
awo
awo's Avatar
Ops... sory :S wrong Tuborials :S
Posted on Thursday 15th November 2007 at 09:35 PM
awo
awo's Avatar
the code is not good!!!!

i can take -10000000000 points in the Withdraw and get the points :S
Posted on Wednesday 24th October 2007 at 11:46 PM
darklight19
darklight19's Avatar
I can't get this to work, it's just making the page blank. I looked at the code counted the brackets, changed some code. And still...nothing
Posted on Tuesday 17th July 2007 at 06:31 AM
gbt91
gbt91's Avatar
lol code function isnt working :S
Posted on Tuesday 17th July 2007 at 06:31 AM
gbt91
gbt91's Avatar
Code
ALTER TABLE `members` ADD `*New Field Name*` VARCHAR( 225 ) NOT NULL,
Posted on Tuesday 17th July 2007 at 06:30 AM
gbt91
gbt91's Avatar
Skill noobs can think it's all here but you forgot to add this xD
Code
ALTER TABLE `members` ADD `points` VARCHAR( 225 ) NOT NULL
Posted on Saturday 30th June 2007 at 01:02 PM
cyruswu
cyruswu's Avatar
Almost scared me. Thank god no rip!