2

我真的不知道如何解释我想要什么,但我会尝试。我知道我的代码很糟糕而且一团糟,我真的很糟糕:/任何帮助将不胜感激。

我正在为我的游戏制作商店,并且有一个数据库,其中列出了商店中口袋妖怪的口袋妖怪/价格/类型/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 />";
    }
?>
4

1 回答 1

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);
于 2013-11-06T09:31:53.510 回答