2
我真的不知道如何解釋我想要的,但我會嘗試。我知道我的代碼是可怕的,一團糟,我真的很糟糕:/任何幫助,將不勝感激。使用一種形式的多個ID
我正在爲我的遊戲開店,並且有一個數據庫,其中列出了店內寵物小精靈的口袋妖怪/價格/類型/ 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 />";
}
?>
你應該用正確的縮進開始。 – 2013-03-27 01:17:04
你也應該使用PDO,如果你可以幫忙的話,'mysql_ *'函數被官方棄用。學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – 2013-03-27 01:24:54
你的代碼完全在壞結構..?會介意解釋你的代碼如何從選擇提交到submittin? – 2013-03-27 01:32:09