Citrix Posted August 19, 2014 Share Posted August 19, 2014 Hello. I've been having trouble with this trade system not working(my friend made it). Most of it is functioning properly, except the part where it's supposed to show your partners pokemon box. Here is the code: <?php require_once("top_header.php"); if(!isset($_GET["p"]) && !isset($_GET["id"]) && !isset($_GET["submit"])) { ?> <form action="trading.php" method="get"> Please enter the ID of the person you would like to trade:<br /> <input type="text" name="p" /><br /> <input type="submit" value="Continue!" /><br /> </form> <table width=100%> <tr> <td class="header">Trade Partners:</td> <td class="header">Open Trades:</td> </tr> <?php $check1 = "SELECT trade_id, starter_id FROM trades WHERE partner_id = $id AND status = 0"; $check2 = mysql_query($check1); while($row = mysql_fetch_array($check2)) { $ass = mysql_fetch_array(mysql_query("SELECT username FROM users WHERE id = {$row["starter_id"]}")); echo "<tr>"; echo "<td class=into>"; echo $ass["username"]; echo "</td>"; echo "<td class=into>"; echo "<a href=trading.php?id={$row["trade_id"]}>View Trade!</a>"; echo "</td>"; echo "</tr>"; } ?> <tr> <td class="header">Created To:</td> <td class="header">Options:</td> </tr> <?php $check1 = "SELECT trade_id, partner_id FROM trades WHERE starter_id = $id AND status = 0"; $check2 = mysql_query($check1); while($row = mysql_fetch_array($check2)) { $ass = mysql_fetch_array(mysql_query("SELECT username FROM users WHERE id = {$row["partner_id"]}")); echo "<tr>"; echo "<td class=into>"; echo $ass["username"]; echo "</td>"; echo "<td class=into>"; echo "<a href=delete.php?id={$row["trade_id"]}>Delete Trade!</a>"; echo "</td>"; echo "</tr>"; } ?> </table> <?php } else if(isset($_GET["p"])) { $check = mysql_num_rows(mysql_query("SELECT username FROM users WHERE id = ".$_GET['p']."")); if($check <= 0) { echo "Please do not try to trade non existant users!"; include('bottom_layout.php'); die(); } ?> <form action="trading.php?submit" method="post"> <b>Your Pokemon:</b><br> <select width="100px" size=15 name="starter[]" multiple="multiple"> <option value="0" selected>None</option> <?php $query = mysql_query("SELECT id, nickname, level FROM pokemon WHERE owner_id= $id AND slot = 7"); while($info = mysql_fetch_assoc($query)) { ?> <option value="<?php echo $info["id"] ?>"><?php echo $info["nickname"] ?> level:<?php echo $info["level"]?></option> <?php } ?> </select> <br><br><br> <b>Partners Pokemon</b><br> <select width="100px" size=15 name="partner[]" multiple="multiple"> <option value="0" selected>None</option> <?php $p = htmlentities($_GET["p"]); $sql = "SELECT id, gender, pokedex_id, type, level FROM pokemon WHERE owner_id = $p AND slot = 7 AND status = 1"; $starter_pokemon = mysql_query($sql); while($row = mysql_fetch_assoc($starter_pokemon)) { $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id={$row["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id={$row["type"]}")); $name = $type["name"].$name["name"]; ?> <option value="<?php echo $info["id"] ?>"><?php echo $info["nickname"] ?> level:<?php echo $info["level"]?></option> <?php } ?> </select><br /> <input type="submit" value="Send Trade!" /> <input type="hidden" name="p_id" value="<?php echo $_GET["p"];?>" /> </form> <?php } else if(isset($_GET["submit"])) { $status = 0; $partner = mysql_real_escape_string($_POST["p_id"]); foreach($_POST["starter"] as $pokemon) { $pokemon = mysql_real_escape_string($pokemon); $result = mysql_query("SELECT id FROM pokemon WHERE owner_id = $id AND id = $pokemon"); if(mysql_num_rows($result) == 0 && $pokemon != 0) { $status = 5; } } foreach($_POST["partner"] as $pokemon) { $pokemon = mysql_real_escape_string($pokemon); $result = mysql_query("SELECT id FROM pokemon WHERE owner_id = $partner AND id = $pokemon"); if(mysql_num_rows($result) == 0 && $pokemon != 0) { $status = 5; } } $starter_pokemon = json_encode($_POST["starter"]); $partner_pokemon = json_encode($_POST["partner"]); if($starter_pokemon == "[\"0\"]" && $partner_pokemon == "[\"0\"]") { echo "Sorry, one of you has to be trading something!"; } $sql = "INSERT INTO trades (starter_id, starter_pokemon, partner_id, partner_pokemon, status) VALUES ($id, '".mysql_real_escape_string($starter_pokemon)."', $partner, '".mysql_real_escape_string($partner_pokemon)."', $status)"; mysql_query($sql); echo "Trade created!"; } else if(isset($_GET["id"])) { $trade = mysql_real_escape_string($_GET["id"]); $sql = "SELECT * FROM trades WHERE trade_id = $trade"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $starter_pokemon = json_decode($row["starter_pokemon"]); $partner_pokemon = json_decode($row["partner_pokemon"]); echo "<h3>You are Trading:</h3>"; foreach($partner_pokemon as $pokeid) { $pokeinfo = mysql_fetch_assoc(mysql_query("SELECT pokedex_id, gender, type, level FROM pokemon WHERE id = $pokeid")); $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id = {$pokeinfo["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id = {$pokeinfo["type"]}")); echo $type["name"].$name["name"]." ({$pokeinfo["gender"]}) (Level:{$pokeinfo["level"]})<br />"; } echo "<h3>Your Partner is Trading:</h3>"; foreach($starter_pokemon as $pokeid) { $pokeinfo = mysql_fetch_assoc(mysql_query("SELECT pokedex_id, gender, type, level FROM pokemon WHERE id = $pokeid")); $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id = {$pokeinfo["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id = {$pokeinfo["type"]}")); echo $type["name"].$name["name"]."({$pokeinfo["gender"]}) (Level:{$pokeinfo["level"]})<br />"; } ?> <br><br> <a href=complete.php?id=<?php echo $row['trade_id']; ?>>Complete the trade!</a><br><a href=delete.php?id=<?php echo $row['trade_id']; ?>>Delete the trade!</a> </table> <?php } require_once("bottom_layout.php"); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted August 19, 2014 Share Posted August 19, 2014 A description of your problem is generally helpful. Quote Link to comment Share on other sites More sharing options...
Citrix Posted August 19, 2014 Author Share Posted August 19, 2014 Forgive me, I thought I put it in there. xD Well, the issue seems to be that when I'm trading with someone, their pokemon box is empty, when it isn't supposed to be. Your pokemon works fine, and lists the pokemon in your box, but where it's supposed to print out the person's box of whom your trading with, it just shows None(which is an option). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.