FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Points Scripts





DanielXP
I have this points script whit my members area and now im trying to make it so users can send points this is my sendpoints.php file:

Code:
<?php
    if($points < $amount) {

     echo "You can't afford this!";
   } else {

$add = mysql_query("SELECT * FROM users WHERE username = '".$logged['username']."'" or die(mysql_error());
$add = mysql_fetch_array($add) or die(mysql_error());

$points = $add['points'] - $amount;
echo "";
$update = mysql_query("UPDATE users SET points = '".$points."' WHERE username = '".$logged['username']."'" or die(mysql_error());



$add = mysql_query("SELECT * FROM users WHERE username = '"$sendto"'" or die(mysql_error());
$add = mysql_fetch_array($add) or die(mysql_error());

$points = $add['points'] + $amount;
echo "You sent $amount to $sendto";
// Or something like that. [You edit]
$update = mysql_query("UPDATE users SET points = '".$points."' WHERE username = '".$logged['username']."'" or die(mysql_error());


$title = Points;
$content = $logged['username'] Sent you $amount Points!;
$getusers = mysql_query("SELECT * FROM users");
while($r=mysql_fetch_array($getusers)){
$sendpm = mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `date` ) VALUES ('$title','$content','$r[username]','$logged[username]','NOW()')") or die("Oh great, you broke it!");

   } else {

echo "Points could not be sent!";

?>


But i keep getting this

Parse error: parse error, unexpected ';' in /home/leos4h/public_html/members/sendpoints.php on line 7

Please help!
shamil
You haven't closed the paranthesis when calling mysql_query function each time.
Code:
$add = mysql_query("SELECT * FROM users WHERE username = '".$logged['username']."'" or die(mysql_error());

it must be
Code:
$add = mysql_query("SELECT * FROM users WHERE username = '".$logged['username']."'") or die(mysql_error());


Correct such errors in the page.
DanielXP
I keep getting this now

Parse error: parse error, unexpected T_VARIABLE in /home/leos4h/public_html/members/sendpoints.php on line 16
shamil
You haven't put dots around variable. Also I told to close right paranthesis.
Code:
$add = mysql_query("SELECT * FROM users WHERE username = '"$sendto"'" or die(mysql_error());
it must be
Code:
$add = mysql_query("SELECT * FROM users WHERE username = '".$sendto."'") or die(mysql_error());


It says in which line the error is. So you can find the error if you know a little php. It makes me think that you don't know anything in php. Please start to learn with online tutorials. Than wasting your time on posting so easy questions that you can find it youself if you study a little.
You must know what php is before managing php codes. You are talking to person without knowing his/her language Wink
DanielXP
I keep getting this error

Parse error: parse error, unexpected T_ELSE in /home/leos4h/public_html/members/sendpoints.php on line 40

with this code

Code:
<?
   ob_start();
   include("config.php");
?>
<?php
$sendto = $_POST[sendto];
$amount = $_POST[amount];
?>
<?php
    if($points < $amount) {

     echo "You do not have enough points!";
   } else {


$add = mysql_query("SELECT * FROM users WHERE username = '".$logged['username']."'") or die(mysql_error());
$add = mysql_fetch_array($add) or die(mysql_error());

$points = $add['points'] - $amount;
echo "";
$update = mysql_query("UPDATE users SET points = '".$points."' WHERE username = '".$logged['username']."'") or die(mysql_error());



$add = mysql_query("SELECT * FROM users WHERE username = '".$sendto."'") or die(mysql_error());
$add = mysql_fetch_array($add) or die(mysql_error());

$points = $add['points'] + $amount;
echo "You sent $amount to $sendto";
// Or something like that. [You edit]
$update = mysql_query("UPDATE users SET points = '".$points."' WHERE username = '".$logged['username']."'") or die(mysql_error());


$title = Points;
$content = "$logged[username] sent you $amount points!";
$getusers = mysql_query("SELECT * FROM users");
while($r=mysql_fetch_array($getusers)){
$sendpm = mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `date` ) VALUES ('$title','$content','$r[username]','Points','NOW()')") or die("Oh great, you broke it!");
}
   } else {

echo "Points could not be sent!";
}
?>
mathiaus
http://frihost.pastebin.com/729895
everything else explained in reply PM
BlackSkad
It'll give a lot more (logical) errors, you know.
  • Did you know that I can increase my own points with that script? Just input a negative amount.
  • Why sending a message to all the users while only 1 get points?
  • What is the first $point var? It'll be 0 in every case, and thus less then $amount. There will never be points donated to anybody.
  • What happens when the system fails to update the points of the receiver? The points donated disappear into nothingness. They should be re-added to the account of the one who donates.


I took the liberty to rewrite your whole script and fix all those things. Some errors are stille possible though, I didn't had the chance to test it.The code should be rather clear, if there are questions, just ask Smile
Code:
<?php

/*************
 * get the $logged['username'] var
 *************/
$logged['username'] = $_SESSION['username'];

/*************
 * get the $amount var
 * It has to be a number (duh), and it has to be larger then
 * 0. If not, the senders points will increase and those from
 * the receiver will decrease.
 *************/
//check if the provided amount is a numeric value (i.e. a number)
if (is_numeric($_POST['amount'])) {
   $amount = (int) $_POST['amount'];
   //check if the number is bigger then 0
   if ($amount < 0) {
      //notify the user and abort the script
      echo 'The amount must be larger then 0!';
      exit;
   }
} else {
   //notify the user and abort the script
   echo 'The amount must be an integer!';
   exit;
}

/*************
 * get the $sendto var
 *************/
$sendto = $_POST['sendto'];

$checkPointsSQL = "UPDATE users SET points = points - $amount WHERE username = '" . $logged['username'] . "' AND points >= $amount LIMIT 1";
$checkPoints = mysql_query ($checkPointsSQL)
   or die ("Sorry, the system was unable request the update-data from the database. (" . mysql_error() . ")");

//If the number of rows that were affected from the update-action == 1
if (mysql_affected_rows() == 1) {

   //everything's ok
   //give the points to the receiver and send him a pm
   $donateSQL = "UPDATE users SET points = points + $amount WHERE username = $sendto LIMIT 1";
   $donate = mysql_query ($donateSQL)
      or echo ("Sorry, the system was unable donate the points to $sendto. (" . mysql_error() . ")");

   //check if there was no error
   if (mysql_errno() == 0) {
      //donating went ok, send pm
      $pmTitle = "Donation from " . $logged['username'];
      $pmMessage = $logged['username'] . " has donated $amount points to you.";
      $pmSQL = "INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `date` ) VALUES ('$pmTitle','$pmMessage','$sendto','" . $logged['username'] . "','" . time() . "')";
      $pm = mysql_query ($pmSQL)
         or echo ("$sendto received your donation but has not been notified about it! (" . mysql_error() . ")");
         
      echo "$sendto has received your donation and has been notifyed.";
   } else {
      //donating went wrong, so re-add the points to the account of the one who donates.
      $reversePointsSQL = "UPDATE users SET points = points + $amount WHERE username = '" . $logged['username'] . "' LIMIT 1";
      $reversePoints = mysql_query ($reversePointsSQL);

      echo "$sendto did not receive your donation. No points should be deducted from your account.";
   }
} else {
   echo "Sorry, you didn't have enough points to donate that amount of points to someone.";
}
?>


If you are interested, I could write a script in which you can donate to multiple users at a time (just pm me).
BlackSkad
DanielXP
Theres an error on line 45 unexpected T_ECHO

Line 45:
Code:
      or echo ("Sorry, the system was unable donate the points to $sendto. (" . mysql_error() . ")");
shamil
DanielXP wrote:
Theres an error on line 45 unexpected T_ECHO

Line 45:
Code:
      or echo ("Sorry, the system was unable donate the points to $sendto. (" . mysql_error() . ")");


Change echo keyword to die in that line. There are two echos need to be replaced.
Code:
      or die ("Sorry, the system was unable donate the points to $sendto. (" . mysql_error() . ")");
BlackSkad
Damn, forgot that echo-ing after or isn't possible. But don't change it to die, remove the 'or ...;' If you just die, you'll have bug in your code: when someone donates, the points are deducted; if the system then fails update the points of the receiver, those points are lost.
Just change those lines to (the @blocks the errors from mysql_error):
Code:
... = @mysql_query('...');
DanielXP
BlackSkad wrote:
Just change those lines to (the @blocks the errors from mysql_error):
Code:
 ... = @mysql_query('...');


I don't understand
Related topics
[java scripts ] Multimedia
[ java scripts ] email service
[java scripts] System information
Strange Fire fox problem
points...
points
Diabki II shop for points
Points drop rate increased?
One More Question (About Points and FRIH$)
Have you built GreaseMonkey scripts for FireFox
Greasemonkey Scripts
[java scripts] Text effect , img ....
Mod's Installed and Custom PHP Scripts Made
Changements to the Points/frih$ system (Discuss)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.