Reputation: 897
I am trying to display two sets of data from a table. I'm making a shop for my game, and have a database that lists the pokemon/price/type/id of the pokemon in the shop. Right now I have it almost working, it displays all the pokemon in the shop and they all have a buy button underneath them, but for some reason no matter what pokemon you try to buy it only buys the one on the top of the list. I hope I explained it well enough here is my code.
if ($_POST['A'] == '1' ) {
$token= mysql_real_escape_string($_POST['token']);
$tokenn = strip_tags($token);
$sql234 = "SELECT * FROM ticketshop";
$result2 = mysql_query("SELECT * FROM ticketshop");
while($row2 = mysql_fetch_array($result2)){
$sql23 = "SELECT * FROM users WHERE username='".$_SESSION['username']."')";
$result = mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'");
while($row = mysql_fetch_array($result)){
echo "You have ".$row['ticket']." Tickets" ;
echo "<p></p>" ;
if (isset($_POST['slot1'])) {
if ($row['ticket'] >= $row2['price']) {
echo "You have bought ".$row2['pokemon']."" ;
mysql_query("UPDATE users SET ticket=ticket-".$row2['price']." WHERE username='".$_SESSION['username']."'")
or die(mysql_error());
mysql_query("INSERT INTO user_pokemon
(pokemon, belongsto, exp, time_stamp, slot, level, type) VALUES ('".$row2['pokemon']."','".$_SESSION['username']."', 100,'".time()."','0', '5', '".$row2['type']."' )")
or die(mysql_error());
} else {
echo "You can't afford ".$row2['pokemon']."";
}
}
}
}
Upvotes: 0
Views: 78
Reputation: 23500
You are getting the error because you are closing connection to database and after you try to fetch result from second query which ends up with the error
<?php } /* mysql_close($conn);*/ /*comment or remove closing connection*/ ?>
<p><b>Listing of pending applications</b></p>
Then I would like to remember you that mysql_
functions are deprecated so i would advise you to switch to mysqli
or PDO
.
Upvotes: 1