Page 1 of 2
API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 7:38 am
by PokerFreak
Hello, I have a form where someone submits a username(account name) and information will be given accordingly. This is the code :
Code: Select all
$account = $_POST['account'];
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
echo "Username: " . $api["Player"] . "</br>Balance: " . $api["Balance"] . " ";
It works. But when i try to put the code in a function no info is displayed. Any Help ?
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 8:42 am
by Kent Briggs
PokerFreak wrote:
It works. But when i try to put the code in a function no info is displayed. Any Help ?
Show us the function you wrote so we can see.
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 8:56 am
by PokerFreak
Code: Select all
function playerInfo() {
$account = $_POST['account'];
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
echo "Username: " . $api["Player"] . "</br>Balance: " . $api["Balance"] . " ";
}
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 9:37 am
by Kent Briggs
And the code where you call the function?
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 9:47 am
by PokerFreak
Code: Select all
<?php
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
if($api['PW'] != $pass) {
header("Location: cashout.php?flag=wrong");
}
else {
playerInfo();
$params = "Password=$pw&Command=AccountsDecBalance&Player=$account&Balance=$balance";
}
?>
If I paste the content of the function in the "else { }" it works. But if I call it through a function, it doesn't.
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 10:06 am
by Kent Briggs
PokerFreak wrote:
If I paste the content of the function in the "else { }" it works. But if I call it through a function, it doesn't.
Where are you placing the actual function? You didn't show it here.
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 10:19 am
by PokerFreak
PokerFreak wrote:Code: Select all
else {
playerInfo();
$params = "Password=$pw&Command=AccountsDecBalance&Player=$account&Balance=$balance";
}
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 10:52 am
by Kent Briggs
No, I see where you are calling the playerInfo() function. But where are you placing the actual function code. You have yet to show a complete example that contains everything. Try putting:
echo "test";
as the first line in your function. If that's not showing up then your function is not being called.
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 10:55 am
by Kent Briggs
PokerFreak wrote:Code: Select all
$params = "Password=$pw&Command=AccountsDecBalance&Player=$account&Balance=$balance";
Also, what is the purpose of this line? It's not doing anything and it's not even a correct call for the AccountsDecBalance command anyway.
Re: API Player Info in PHP Function ?
Posted: Thu Apr 28, 2011 11:09 am
by PokerFreak
That's the Full Page.
Code: Select all
<html>
<?php include "API.php";
$pass = $_POST['pass'];
$account = $_POST['account'];
function playerInfo() {
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
echo "Username: " . $api["Player"] . "</br>Balance: " . $api["Balance"] . " ";
}
?>
<head>
<div align="left">
<h3><a href="12.php">Main</a></h3></div>
<center><img src="spades.jpg" alt="logo" width="150" height="150" /></center>
<?php echo "<br/><b>Your IP Address is $ip</b>"; ?>
</head>
<body>
<br/><br/><br/><br/><br/><br/><br/><br/>
<?php
$params = "Password=$pw&Command=AccountsGet&Player=$account";
$api = Poker_API($url,$params,true);
if($api['PW'] != $pass) {
header("Location: cashout.php?flag=wrong");
}
else {
playerInfo();
}
?>
</br></br></br>
<form method="post" name="auth" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<center>
<table width="400" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="50" align="right">Enter Balance </td>
<td><input name="balance" type="text" id="balance"></td>
</tr>
<tr>
<td width="150" align="right"> </td>
<td>
<input type="submit" name="Submit" value="Submit"></left></td>
</tr>
</center>
</table>
</form>
</body>
</html>