Dragon Blade Posted October 29, 2013 Share Posted October 29, 2013 Hello all, I have a problem when ever I dump the item it always come out as blank? Any reasons why too? And if anyone could help me out that would be great! <?php session_start(); require "global_func.php"; if ($_SESSION['loggedin'] == 0) { header("Location: login.php"); exit; } $userid = $_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is = mysql_query( "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid", $c) or die(mysql_error()); $ir = mysql_fetch_array($is); check_level(); $fm = money_formatter($ir['money']); $cm = money_formatter($ir['crystals'], ''); $lv = date('F j, Y, g:i a', $ir['laston']); $h->userdata($ir, $lv, $fm, $cm); $h->menuarea(); echo '<h3><u>Dump</u></h3><hr width="75%" />'; switch($_GET['step']) { case "dump": dump(); break; case "dump2": dump2(); break; case "search": search(); break; default: index(); } function index() { global $db, $ir, $c, $h, $userid; $num = mysql_query("SELECT * FROM `dump`"); echo '<br />Welcome to the dump, people all over the city come here to dump there crap. <br />There are currently <font color=blue><b>'.mysql_num_rows($num).'</b></font> items that are dumped.<br /><br /> > <a href="dump.php?step=search">Search the dump!</a><br /><br />'; } function dump2() { global $db, $ir, $c, $h, $userid; if($_POST) { $itemid = abs((int) $_GET['id']); $amount = abs((int) $_POST['amount']); $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = {$ir['userid']} and inv_itemid = ".$itemid.""); $data = mysql_fetch_array($query); if($_POST['amount'] < 1) { echo '<br />You have to dump something to be able to dump it!<br /><br />'; } if($data['inv_qty'] < $_POST['amount']) { echo '<br />You do not have that many of this item to dump!<br /><br />'; } else { $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = ".$userid.""); $data = mysql_fetch_array($query); item_remove($userid, $itemid, $_POST['amount']); for($i=1; $i <= $_POST['amount']; $i++) { mysql_query("INSERT INTO `dump` (dumpID, itmID, dumperID) VALUES (NULL, ".$itemid.", ".$userid.")"); } echo '<br />You have dumped '.$_POST['amount'].' '.getitmname($itemid).'(s)!<br /><br />'; } } } function dump() { global $db, $ir, $c, $h, $userid; echo " <br />Please pick which items you would like to dump.<br /><br /><hr width='75%' />"; echo" <table width='75%' cellspacing='1' class='table'><tr style='background:gray'> <th width='70%'>Name</th><th>Qty</th><th width='15%'>Amount</th><th width='15%'>Trash</th></tr>"; $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = ".$userid.""); while($data=mysql_fetch_array($query)) { echo" <td>".getitmname($data['inv_itemid'])." </td> <td>x".$data['inv_qty']."</td> <td><input type=text name='amount' size='5' maxlength='5' value='0'></td> <form action=dump.php?step=dump2&id=".$data['inv_itemid']." method='post'> <td><input type='submit' value='Dump' /></td> </tr>"; } echo '<br /></form></table>'; } function search() { global $db, $ir, $c, $h, $userid; $energy=(int) ($ir['maxenergy']/100*10); $rfc =rand(1,5); $num = mysql_query("SELECT * FROM `dump`"); if ($energy >= $ir['energy']+1) { echo '<br />You do not have enough energy to search the dump any longer.<br /><br />'; } else if($rfc != 3) { echo '<br />You searched the dump for hours but couldn\'t find anything.<br /><br />> <a href="dump.php?step=search">Search again!</a><br /><br />'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = ".$userid.""); } else if(mysql_num_rows($num) < 1) { echo '<br />You searched the dump for hours but couldn\'t find anything.<br /><br />> <a href="dump.php?step=search">Search again!</a><br /><br />'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = ".$userid.""); } else { $query = mysql_query("SELECT * FROM `dump` ORDER BY RAND() LIMIT 0,1;"); while($data = mysql_fetch_array($query)) { $getname = mysql_query("SELECT `username` FROM `users` WHERE `userid` = ".$data['dumperID']."", $c); if(mysql_num_rows($getname)) { $a = mysql_fetch_array($getname); $name = '<a href="viewuser.php?u='.$data['dumperID'].'" alt="'.$a['username'].'">'.$a['username'].'</a>'; } else { $name = "Unknown"; } echo '<br />You searched the dump and find a <font color = gold>'.getitmname($data['itmID']).'</font> that was dumped by '.$name.'!'; item_add($userid, $data['itmID'], 1); mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = ".$userid.""); mysql_query("DELETE FROM `dump` WHERE `dumpID`= ".$data['dumpID'].""); } echo'<br /><br />> <a href="dump.php?step=search">Search again!</a><br /><br />'; } } echo ' <hr width="75%" /><table width="75%"> <tr><td width="50%" align="center"> > <a href="dump.php">Back</a> </td><td width="50%" align="center"> > <a href="dump.php?step=dump" alt="Dump your items!">Dump Items</a> </td></tr></table><hr width="75%" /><br />'; function getitmname($itmid) { global $db, $ir, $c, $h, $userid; $getitem = mysql_query("SELECT `itmname` FROM `items` WHERE `itmid` = ".$itmid.""); if(mysql_num_rows($getitem)) { $itemData = mysql_fetch_array($getitem); $item = $itemData['itmname']; return $item; } } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
sniko Posted October 29, 2013 Share Posted October 29, 2013 Perhaps adopt some sort of naming convention for your variablesHungarian camel notation will help 3rd party developers, such as those on a forum - like this one - debug your horribly presented code. It'll help you debug your code faster [*]Indent your code logically. It could be the forum software rendering it incorrectly, however I doubt it It will help you debug your code faster [*]Use an IDE or advanced text-editor (you could be that you're already using one, I don't know) I don't mean Notepad. [*]Move away from mysql At the very least, move to MySQLi You're bound to the mysql databaseWhat if you wanted to move to ...say... MongoDB? You'd have to rewrite everything [*]Research into PDO Or a 3rd party database class Anyhow, here's your code indented properly. <?php session_start(); require "global_func.php"; if ($_SESSION['loggedin'] == 0) { header("Location: login.php"); exit; } $userid = $_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is = mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid", $c) or die(mysql_error()); $ir = mysql_fetch_array($is); check_level(); $fm = money_formatter($ir['money']); $cm = money_formatter($ir['crystals'], ''); $lv = date('F j, Y, g:i a', $ir['laston']); $h->userdata($ir, $lv, $fm, $cm); $h->menuarea(); echo '<h3><u>Dump</u></h3><hr width="75%" />'; switch ($_GET['step']) { case "dump": dump(); break; case "dump2": dump2(); break; case "search": search(); break; default: index(); } function index() { global $db, $ir, $c, $h, $userid; $num = mysql_query("SELECT * FROM `dump`"); echo 'Welcome to the dump, people all over the city come here to dump there crap. There are currently <font color=blue><b>' . mysql_num_rows($num) . '</b></font> items that are dumped. > <a href="dump.php?step=search">Search the dump!</a>'; } function dump2() { global $db, $ir, $c, $h, $userid; if ($_POST) { $itemid = abs((int) $_GET['id']); $amount = abs((int) $_POST['amount']); $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = {$ir['userid']} and inv_itemid = " . $itemid . ""); $data = mysql_fetch_array($query); if ($_POST['amount'] < 1) { echo 'You have to dump something to be able to dump it!'; } if ($data['inv_qty'] < $_POST['amount']) { echo 'You do not have that many of this item to dump!'; } else { $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = " . $userid . ""); $data = mysql_fetch_array($query); item_remove($userid, $itemid, $_POST['amount']); for ($i = 1; $i <= $_POST['amount']; $i++) { mysql_query("INSERT INTO `dump` (dumpID, itmID, dumperID) VALUES (NULL, " . $itemid . ", " . $userid . ")"); } echo 'You have dumped ' . $_POST['amount'] . ' ' . getitmname($itemid) . '(s)!'; } } } function dump() { global $db, $ir, $c, $h, $userid; echo "Please pick which items you would like to dump.<hr width='75%' />"; echo "<table width='75%' cellspacing='1' class='table'><tr style='background:gray'> <th width='70%'>Name</th><th>Qty</th><th width='15%'>Amount</th><th width='15%'>Trash</th></tr>"; $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = " . $userid . ""); while ($data = mysql_fetch_array($query)) { echo"<td>" . getitmname($data['inv_itemid']) . " </td> <td>x" . $data['inv_qty'] . "</td> <td><input type=text name='amount' size='5' maxlength='5' value='0'></td> <form action=dump.php?step=dump2&id=" . $data['inv_itemid'] . " method='post'> <td><input type='submit' value='Dump' /></td> </tr>"; } echo '</form></table>'; } function search() { global $db, $ir, $c, $h, $userid; $energy = (int) ($ir['maxenergy'] / 100 * 10); $rfc = rand(1, 5); $num = mysql_query("SELECT * FROM `dump`"); if ($energy >= $ir['energy'] + 1) { echo 'You do not have enough energy to search the dump any longer.'; } else if ($rfc != 3) { echo 'You searched the dump for hours but couldn\'t find anything.> <a href="dump.php?step=search">Search again!</a>'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); } else if (mysql_num_rows($num) < 1) { echo 'You searched the dump for hours but couldn\'t find anything.> <a href="dump.php?step=search">Search again!</a>'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); } else { $query = mysql_query("SELECT * FROM `dump` ORDER BY RAND() LIMIT 0,1;"); while ($data = mysql_fetch_array($query)) { $getname = mysql_query("SELECT `username` FROM `users` WHERE `userid` = " . $data['dumperID'] . "", $c); if (mysql_num_rows($getname)) { $a = mysql_fetch_array($getname); $name = '<a href="viewuser.php?u=' . $data['dumperID'] . '" alt="' . $a['username'] . '">' . $a['username'] . '</a>'; } else { $name = "Unknown"; } echo 'You searched the dump and find a <font color = gold>' . getitmname($data['itmID']) . '</font> that was dumped by ' . $name . '!'; item_add($userid, $data['itmID'], 1); mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); mysql_query("DELETE FROM `dump` WHERE `dumpID`= " . $data['dumpID'] . ""); } echo'> <a href="dump.php?step=search">Search again!</a>'; } } echo ' <hr width="75%" /><table width="75%"> <tr><td width="50%" align="center"> > <a href="dump.php">Back</a> </td><td width="50%" align="center"> > <a href="dump.php?step=dump" alt="Dump your items!">Dump Items</a> </td></tr></table><hr width="75%" />'; function getitmname($itmid) { global $db, $ir, $c, $h, $userid; $getitem = mysql_query("SELECT `itmname` FROM `items` WHERE `itmid` = " . $itmid . ""); if (mysql_num_rows($getitem)) { $itemData = mysql_fetch_array($getitem); $item = $itemData['itmname']; return $item; } } $h->endpage(); ?> I have a problem when ever I dump the item it always come out as blank? What is it? - - - Updated - - - Perhaps adopt some sort of naming convention for your variablesHungarian camel notation will help 3rd party developers, such as those on a forum - like this one - debug your horribly presented code. It'll help you debug your code faster [*]Indent your code logically. It could be the forum software rendering it incorrectly, however I doubt it It will help you debug your code faster [*]Use an IDE or advanced text-editor (you could be that you're already using one, I don't know) I don't mean Notepad. [*]Move away from mysql At the very least, move to MySQLi You're bound to the mysql databaseWhat if you wanted to move to ...say... MongoDB? You'd have to rewrite everything [*]Research into PDO Or a 3rd party database class Anyhow, here's your code indented properly. <?php session_start(); require "global_func.php"; if ($_SESSION['loggedin'] == 0) { header("Location: login.php"); exit; } $userid = $_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is = mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid", $c) or die(mysql_error()); $ir = mysql_fetch_array($is); check_level(); $fm = money_formatter($ir['money']); $cm = money_formatter($ir['crystals'], ''); $lv = date('F j, Y, g:i a', $ir['laston']); $h->userdata($ir, $lv, $fm, $cm); $h->menuarea(); echo '<h3><u>Dump</u></h3><hr width="75%" />'; switch ($_GET['step']) { case "dump": dump(); break; case "dump2": dump2(); break; case "search": search(); break; default: index(); } function index() { global $db, $ir, $c, $h, $userid; $num = mysql_query("SELECT * FROM `dump`"); echo 'Welcome to the dump, people all over the city come here to dump there crap. There are currently <font color=blue><b>' . mysql_num_rows($num) . '</b></font> items that are dumped. > <a href="dump.php?step=search">Search the dump!</a>'; } function dump2() { global $db, $ir, $c, $h, $userid; if ($_POST) { $itemid = abs((int) $_GET['id']); $amount = abs((int) $_POST['amount']); $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = {$ir['userid']} and inv_itemid = " . $itemid . ""); $data = mysql_fetch_array($query); if ($_POST['amount'] < 1) { echo 'You have to dump something to be able to dump it!'; } if ($data['inv_qty'] < $_POST['amount']) { echo 'You do not have that many of this item to dump!'; } else { $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = " . $userid . ""); $data = mysql_fetch_array($query); item_remove($userid, $itemid, $_POST['amount']); for ($i = 1; $i <= $_POST['amount']; $i++) { mysql_query("INSERT INTO `dump` (dumpID, itmID, dumperID) VALUES (NULL, " . $itemid . ", " . $userid . ")"); } echo 'You have dumped ' . $_POST['amount'] . ' ' . getitmname($itemid) . '(s)!'; } } } function dump() { global $db, $ir, $c, $h, $userid; echo "Please pick which items you would like to dump.<hr width='75%' />"; echo "<table width='75%' cellspacing='1' class='table'><tr style='background:gray'> <th width='70%'>Name</th><th>Qty</th><th width='15%'>Amount</th><th width='15%'>Trash</th></tr>"; $query = mysql_query("SELECT * FROM `inventory` WHERE `inv_userid` = " . $userid . ""); while ($data = mysql_fetch_array($query)) { echo"<td>" . getitmname($data['inv_itemid']) . " </td> <td>x" . $data['inv_qty'] . "</td> <td><input type=text name='amount' size='5' maxlength='5' value='0'></td> <form action=dump.php?step=dump2&id=" . $data['inv_itemid'] . " method='post'> <td><input type='submit' value='Dump' /></td> </tr>"; } echo '</form></table>'; } function search() { global $db, $ir, $c, $h, $userid; $energy = (int) ($ir['maxenergy'] / 100 * 10); $rfc = rand(1, 5); $num = mysql_query("SELECT * FROM `dump`"); if ($energy >= $ir['energy'] + 1) { echo 'You do not have enough energy to search the dump any longer.'; } else if ($rfc != 3) { echo 'You searched the dump for hours but couldn\'t find anything.> <a href="dump.php?step=search">Search again!</a>'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); } else if (mysql_num_rows($num) < 1) { echo 'You searched the dump for hours but couldn\'t find anything.> <a href="dump.php?step=search">Search again!</a>'; mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); } else { $query = mysql_query("SELECT * FROM `dump` ORDER BY RAND() LIMIT 0,1;"); while ($data = mysql_fetch_array($query)) { $getname = mysql_query("SELECT `username` FROM `users` WHERE `userid` = " . $data['dumperID'] . "", $c); if (mysql_num_rows($getname)) { $a = mysql_fetch_array($getname); $name = '<a href="viewuser.php?u=' . $data['dumperID'] . '" alt="' . $a['username'] . '">' . $a['username'] . '</a>'; } else { $name = "Unknown"; } echo 'You searched the dump and find a <font color = gold>' . getitmname($data['itmID']) . '</font> that was dumped by ' . $name . '!'; item_add($userid, $data['itmID'], 1); mysql_query("UPDATE `users` SET `energy` = `energy` - {$energy} WHERE `userid` = " . $userid . ""); mysql_query("DELETE FROM `dump` WHERE `dumpID`= " . $data['dumpID'] . ""); } echo'> <a href="dump.php?step=search">Search again!</a>'; } } echo ' <hr width="75%" /><table width="75%"> <tr><td width="50%" align="center"> > <a href="dump.php">Back</a> </td><td width="50%" align="center"> > <a href="dump.php?step=dump" alt="Dump your items!">Dump Items</a> </td></tr></table><hr width="75%" />'; function getitmname($itmid) { global $db, $ir, $c, $h, $userid; $getitem = mysql_query("SELECT `itmname` FROM `items` WHERE `itmid` = " . $itmid . ""); if (mysql_num_rows($getitem)) { $itemData = mysql_fetch_array($getitem); $item = $itemData['itmname']; return $item; } } $h->endpage(); ?> I have a problem when ever I dump the item it always come out as blank? What is it? 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.