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