Jump to content

Recommended Posts

After months of trial and Error I can see the finish line in the distance.

 

As many of you may know, I have been trying to get a IPN script working with paypal, and I have finnally done it. And all their is to do now is get the database querying working, which I am very close to!

 

I'll lay down the facts first, then the code.

 

I have a "paypal - Buy Now Button" it has quite a few values, with the most important one being "playerid" which is my variable that selects the ID of the currently logged in person on my website which is 1 of the post values in the Buy Now Button. which looks like this:

<?php
// Grab Player ID for PayPal
$playerid = $userrow["id"];
?>

that works fine as I can echo it and it grabs the correct ID.

 

Now My Database Querying isnt working just yet, Im guessing I've made a small error somewhere, or have put the wrong qoutes or double qoutes in somewhere. Here is the function with the queries:

<?php
// Supporter Status Function

function supporterstatus() {

include('lib.php');
include('cookies.php');
/*
$link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
$controlrow = mysql_fetch_array($controlquery);
// Login (or verify) if not logged in.
$userrow = checkcookies();
if ($userrow == false) { 
    if (isset($_GET["do"])) {
        if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die('Quiting From Here - couldnt verify'); }
    }
    header("Location: login.php?do=login"); die('Quiting From Here - need to log in'); 
} */

// ---> Select Variables <--- 
$charactername_select = mysql_query("SELECT `charname` FROM `sl_users` WHERE id='$playerid'");
$bank_select = mysql_query("SELECT `bank` FROM `sl_users` WHERE id='$playerid'");
$maxmp_select = mysql_query("SELECT `maxmp` FROM `sl_users` WHERE id='$playerid'");
$maxtp_select = mysql_query("SELECT `maxtp` FROM `sl_users` WHERE id='$playerid'");
$maxhp_select = mysql_query("SELECT `maxhp` FROM `sl_users` WHERE id='$playerid'");
$strength_select = mysql_query("SELECT `strength` FROM `sl_users` WHERE id='$playerid'");
$dexterity_select = mysql_query("SELECT `dexterity` FROM `sl_users` WHERE id='$playerid'");
$experience_select = mysql_query("SELECT `experience` FROM `sl_users` WHERE id='$playerid'");



if(substr($charactername_select, -4) == '~SS~'){
$redd = "";
}
else//if($userrow['charname'] !== $userrow['charname']." ~SS~")
{
$redd = " ~SS~";
}    

    $charn = $charactername_select;
    $bank = $bank_select;
    $maxmp = $maxmp_select;
    $maxtp = $maxtp_select;
    $maxhp = $maxhp_select;
$strengthh = $strength_select;
$dexterityy = $dexterity_select;
$experiencee = $experience_select;

    if ($userrow['verify'] == 1) {
        $charn = $charactername_select.$redd;
        $bank = ceil($bank_select+2500);
        $maxmp = ceil($maxmp_select+25);
        $maxtp = ceil($maxtp_select+25);
        $maxhp = ceil($maxhp_select+25);
	$strengthh = ceil($strength_select+25);
	$dexterityy = ceil($dexterity_select+25);
	$experiencee = ceil($experience_select+100);
        //echo("Transaction Successful!"); 
	}

$con = mysql_connect("localhost","ace_ACE","*****");
if (!$con)
  {
die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ace_sl", $con);

    mysql_query("UPDATE `sl_users` SET `charname`='$charn' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
mysql_query("UPDATE `sl_users` SET `bank`='$bank' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
    mysql_query("UPDATE `sl_users` SET `maxmp`='$maxmp' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
    mysql_query("UPDATE `sl_users` SET `maxtp`='$maxtp' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
    mysql_query("UPDATE `sl_users` SET `maxhp`='$maxhp' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
mysql_query("UPDATE `sl_users` SET `strength`='$strengthh' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
mysql_query("UPDATE `sl_users` SET `dexterity`='$dexterityy' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
mysql_query("UPDATE `sl_users` SET `experience`='$experiencee' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
mysql_query("UPDATE `sl_users` SET `authlevel`='3' WHERE id='".$playerid."'")
or die ("MYSQL ERROR: ".mysql_error()."");
}
?>

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/67191-database-querying/
Share on other sites

You select queries return result sets, not the value from the table. Try

<?php
$sql = "SELECT bank,maxmp,maxtp,maxhp,strength,dexterity,experience FROM `sl_users` WHERE id='$playerid'";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); 
list ($bank,$maxmp,$maxtp,$maxhp,$strength,$dexterity,$experience) = mysql_fetch_row($res);

Link to comment
https://forums.phpfreaks.com/topic/67191-database-querying/#findComment-338447
Share on other sites

I tried:

<?php

$con = mysql_connect("localhost","ace_ACE","*****");
if (!$con)
  {
die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ace_sl", $con);

$sql = "SELECT bank,maxmp,maxtp,maxhp,strength,dexterity,experience FROM `sl_users` WHERE id='60'";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); 
list ($bank,$maxmp,$maxtp,$maxhp,$strength,$dexterity,$experience) = mysql_fetch_row($res);
echo '<br>';
echo "Bank: $bank";
echo '<br>';
echo "MP: $maxmp";
echo '<br>';
echo "TP: $maxtp";
echo '<br>';
echo "HP: $maxhp";
echo '<br>';
echo "Str: $strength";
echo '<br>';
echo "Dex: $dexterity";
echo '<br>';
echo "Exp: $experience";
echo '<br>';

?>

 

and I set the ID to 60, as thats the ID of my test account.

 

and that outputted:

Bank: 35000

MP: 355

TP: 361

HP: 367

Str: 355

Dex: 357

Exp: 1484

 

so that seems to work fine, my script still doesn't want to work though  :-\

 

I was wondering if maybe the queries dont want to execute because maybe PayPal hasn't sent the Player ID across, or I aren't grabbing the $playerid variable correctly?

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/67191-database-querying/#findComment-339134
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.