Hello fellow PHP trained monkeys :D
I am trying to find a way to have a basic CMS management system but to be dynmic on one PHP page only, the most part works for the first time of selecting the username, and then from either add or minus buton.
The error occurs when submitting as it only parses the amount and type, and not the selected username, or current loged in admi session username.
Any ideas how to keep data parsing though the multiple if(isset) ?
~KG171~
<body>
<?php
include('../SQLconfig.php');
$query = "SELECT * FROM players ;";
$result = mysql_query($query);
echo "<table border = ' 0 '>
<tr>
<th>XO Credit Mangement</th>
</tr >";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
$url = "XOCredits.php?username=" . $row['username'];
echo "<td><a href=" . $url . ">"
. $row['id']
. " - "
. $row['rank']
. " - "
. $row['username']
. " - "
. $row['credits']
. "</a></td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
if(isset($_GET['username']))
{
$username = $_GET['username'];
$beforeCredits = $row['credits'];
echo $username . "<a href='XOCredits.php?add'><button>Add Credits</button></a>" . "<a href='XOCredits.php?minus'><button>Minus Credits</button></a>";
}
?>
<?php
if(isset($_GET['add']))
{
$username = $_POST['username'] ;
echo "<u>" . $username . "</u>" ;
echo "
<form action='XOCredits.php?ac' method='post'>
<input type='text' name='username' value='$username'/>
<p>Add Credits Amount:</p>
<input type='text' name='amount' />
<br />
<input type='submit' name='submit' value='Submit' />
</form>
";
}
?>
<?php
if(isset($_GET['minus']))
{
$username = $_POST['username'] ;
echo "<u>" . $username . "</u>" ;
echo "
<form action='XOCredits.php?mc' method='post'>
<p>Take Away Credits Amount:</p>
<input type='text' name='amount' />
<input type='hidden' name='username' value='$username'/>
<br />
<input type='submit' name='submit' value='Submit' />
</form>
";
}
?>
<?php
if(isset($_GET['ac']))
{
$type = "add";
$amount = $_POST['amount'];
$afterCredits = $beforeCredits + $amount ;
$sentFrom = $_SESSION['u_name'];
$sentTo = $_GET['username'];
$query = "INSERT INTO creditlog (from,to,amount,type)
VALUES ('$sentFrom','$sentTo','$afterCredits','$type');";
mysql_query($query) or die (mysql_error());
echo $query;
$credits = $afterCredits;
$query2 = ("UPDATE players SET credits='$credits' WHERE username='$username'
;")or die(mysql_error());
mysql_query($query2);
echo $query2;
}
?>
<?php
if(isset($_GET['mc']))
{
$type = "minus";
$amount = $_POST['amount'];
$afterCredits = $beforeCredits - $amount ;
$sentFrom = $_SESSION['u_name'];
$sentTo = $_GET['username'];
$query = "INSERT INTO creditlog (from,to,amount,type)
VALUES ('$sentFrom','$sentTo','$afterCredits','$type');";
mysql_query($query) or die (mysql_error());
echo $query;
$credits = $afterCredits;
$query2 = ("UPDATE players SET credits='$credits' WHERE username='$username'
;")or die(mysql_error());
mysql_query($query2);
echo $query2;
}
?>
<br /><a href="index.php"><button>Home</button></a>
</body>