Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple ids with one form
    primarykey
    data
    text
    <p>I don't really know how to explain what I want but I'll try. I know my code is horrid and a big mess, I'm just really bad :/ any help would be appreciated.</p> <p>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.</p> <pre><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 "&lt;p&gt;&lt;/p&gt;" ; if (isset($_POST['slot1'])) { if ($row['ticket'] &gt;= $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'].""; } } } } } ?&gt; &lt;?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 '&lt;img src="pokemon/'.$row['type'] .''.$battle_get2['pic'].'" border=0&gt; &lt;/a&gt;' ; $idd= mysql_real_escape_string($row2['id']); $iddd = strip_tags($idd); ?&gt; &lt;/span&gt; &lt;form name="slot1" action="" method="post"&gt; &lt;div align="center"&gt; &lt;p&gt; &lt;span&gt; &lt;select name="A" id="" &gt; &lt;option value="1"&gt;Buy&lt;/option&gt; &lt;/select&gt; &lt;input type="hidden" name="token" id="token" value="&lt;?php echo $iddd ; ?&gt;" /&gt; &lt;br /&gt; &lt;input type="submit" class="submit" value="Accept" name="slot1"&gt; &lt;/span&gt;&lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;span&gt; &lt;?php echo $row ['pokemon']; ?&gt; &lt;/span&gt; &lt;p&gt;&lt;/p&gt; &lt;span&gt; &lt;?php echo "type:"; echo $row ['type']; ?&gt; &lt;/span&gt; &lt;p&gt;&lt;/p&gt; &lt;span&gt; &lt;?php echo "price:"; echo $row['price']; echo "&lt;br /&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload