我真的不知道如何解释我想要的但我会尝试。我知道我的代码很可怕而且很乱,我真的很糟糕:/任何帮助都会受到赞赏。
我正在为我的游戏开店,并且有一个数据库,列出商店中口袋妖怪的口袋妖怪/价格/类型/ ID。现在我几乎工作了,它显示了商店里的所有口袋妖怪,他们都有一个购买按钮,但由于某种原因无论你试图购买什么口袋妖怪,它只会购买列表顶部的那个。我希望我解释得很好,这是我的代码。
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']."";
}
}
}
}
}
?>
<?php
$result = mysql_query("SELECT * FROM ticketshop");
while($row = mysql_fetch_array($result))
{
$sql2 = "SELECT * FROM pokemon WHERE name='".$row['pokemon']."'";
$result2 = mysql_query($sql2) or die(mysql_error());
$battle_get2 = mysql_fetch_array($result2);
echo '<img src="pokemon/'.$row['type'] .''.$battle_get2['pic'].'" border=0>
</a>' ;
$idd= mysql_real_escape_string($row2['id']);
$iddd = strip_tags($idd);
?>
</span>
<form name="slot1" action="" method="post">
<div align="center">
<p>
<span>
<select name="A" id="" >
<option value="1">Buy</option>
</select>
<input type="hidden" name="token" id="token" value="<?php echo $iddd ; ?>" />
<br />
<input type="submit" class="submit" value="Accept" name="slot1">
</span></p>
</div>
</form>
<span>
<?php
echo $row ['pokemon'];
?>
</span>
<p></p>
<span>
<?php
echo "type:";
echo $row ['type'];
?>
</span>
<p></p>
<span>
<?php
echo "price:";
echo $row['price'];
echo "<br />";
}
?>
答案 0 :(得分:0)
Below you are doing wrong:
$sql234 = "SELECT * FROM ticketshop";
$result2 = mysql_query("SELECT * FROM ticketshop");
here you are not adding any conditions for fetching the particular record, please see corrections below:
$sql234 = "SELECT * FROM ticketshop where <<FIELD NAME>> = '".$token."'";
$result2 = mysql_query($sql234);