tittlemouse Posted March 2, 2008 Posted March 2, 2008 here is the code im trying to use on my v2 site <?php include "globals.php"; print "<h3>Item Market</h3>"; switch($_GET['action']) { case "buy": item_buy(); break; case "gift1": item_gift1(); break; case "gift2": item_gift2(); break; case "remove": item_remove(); break; default: imarket_index(); break; } function imarket_index() { global $db,$ir,$c,$userid,$h; print "Viewing all listings... <table width=75% cellspacing=1 class='table'> <tr style='background:gray'> <th>Adder</th> <th>Item</th> <th>Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT im.*, i.*, u.*,it.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid LEFT JOIN users u ON u.userid=im.imADDER LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid ORDER BY i.itmtype, i.itmname ASC"); $lt=""; while($r=$db->fetch_row($q)) { if($lt!=$r['itmtypename']) { $lt=$r['itmtypename']; print "\n<tr style='background: gray;'><th colspan=4>{$lt}</th></tr>"; } if($r['imCURRENCY']=="money") { $price="\$".number_format($r['imPRICE']); } else { $price=number_format($r['imPRICE'])." crystals"; } if($r['imADDER'] == $userid) { $link = "[[url='itemmarket.php?action=remove&ID={$r[']Remove[/url]]"; } else { $link = "[[url='itemmarket.php?action=buy&ID={$r[']Buy[/url]] [[url='itemmarket.php?action=gift1&ID={$r[']Gift[/url]]"; } print "\n<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['itmname']}</td> <td>$price</td> <td>[[url='iteminfo.php?ID={$r[']Info[/url]] $link</td> </tr>"; } print "</table>"; } function item_remove() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT im.*,i.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid WHERE imID={$_GET['ID']} AND imADDER=$userid"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or you are not the owner. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); item_add($userid, $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}"); $db->query("INSERT INTO imremovelogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} removed a {$r['itmname']} from the item market.')"); print "Item removed from market! [url='itemmarket.php']> Back[/url]"; } function item_buy() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}",$c); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } item_add($userid, $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}"); $db->query("UPDATE users SET $curr=$curr-{$r['imPRICE']} where userid=$userid"); $db->query("UPDATE users SET $curr=$curr+{$r['imPRICE']} where userid={$r['imADDER']}"); if($curr=="money") { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for \$".number_format($r['imPRICE']).".",$c); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']}')"); print "You bought the {$r['itmname']} from the market for \$".number_format($r['imPRICE'])."."; } else { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for ".number_format($r['imPRICE'])." crystals.",$c); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for {$r['imPRICE']} crystals from user ID {$r['imADDER']}')"); print "You bought the {$r['itmname']} from the market for ".number_format($r['imPRICE'])." crystals."; } } function item_gift1() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } if($curr=="money") { print "Buying the [b]{$r['itmname']}[/b] for \$".number_format($r['imPRICE'])." as a gift... <form action='itemmarket.php?action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <input type='submit' value='Buy Item and Send Gift' /></form>"; } else { print "Buying the [b]{$r['itmname']}[/b] for ".number_format($r['imPRICE'])." crystals as a gift... <form action='itemmarket.php?action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <input type='submit' value='Buy Item and Send Gift' /></form>"; } } function item_gift2() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_POST['ID']}"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } item_add($_POST['user'], $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_POST['ID']}"); $db->query("UPDATE users SET $curr=$curr-{$r['imPRICE']} where userid=$userid"); $db->query("UPDATE users SET $curr=$curr+{$r['imPRICE']} where userid={$r['imADDER']}"); if($curr=="money") { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for \$".number_format($r['imPRICE']).".",$c); event_add($_POST['user'], "[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought you a {$r['itmname']} from the item market as a gift.",$c); $u=$db->query("SELECT username FROM users WHERE userid={$_POST['user']}"); $uname=$db->fetch_single($u); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); print "You bought the {$r['itmname']} from the market for \$".number_format($r['imPRICE'])." and sent the gift to $uname."; } else { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for ".number_format($r['imPRICE'])." crystals.",$c); event_add($_POST['user'], "[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought you a {$r['itmname']} from the item market as a gift.",$c); $u=$db->query("SELECT username FROM users WHERE userid={$_POST['user']}"); $uname=$db->fetch_single($u); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for {$r['imPRICE']} crystals from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); print "You bought the {$r['itmname']} from the market for ".number_format($r['imPRICE'])." crystals and sent the gift to $uname."; } } $h->endpage(); ?> i carnt get it to work this is what i get Fatal error: Cannot redeclare item_remove() in /home/avfc1993/public_html/global_func.php on line 323 Quote
Guest Anonymous Posted March 2, 2008 Posted March 2, 2008 Re: itemmarket.php help Try.... <?php include "globals.php"; print "<h3>Item Market</h3>"; switch($_GET['action']) { case "buy": item_buy(); break; case "gift1": item_gift1(); break; case "gift2": item_gift2(); break; case "remove": itemm_remove(); break; default: imarket_index(); break; } function imarket_index() { global $db,$ir,$c,$userid,$h; print "Viewing all listings... <table width=75% cellspacing=1 class='table'> <tr style='background:gray'> <th>Adder</th> <th>Item</th> <th>Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT im.*, i.*, u.*,it.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid LEFT JOIN users u ON u.userid=im.imADDER LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid ORDER BY i.itmtype, i.itmname ASC"); $lt=""; while($r=$db->fetch_row($q)) { if($lt!=$r['itmtypename']) { $lt=$r['itmtypename']; print "\n<tr style='background: gray;'><th colspan=4>{$lt}</th></tr>"; } if($r['imCURRENCY']=="money") { $price="\$".number_format($r['imPRICE']); } else { $price=number_format($r['imPRICE'])." crystals"; } if($r['imADDER'] == $userid) { $link = "[[url='itemmarket.php?action=remove&ID={$r[']Remove[/url]]"; } else { $link = "[[url='itemmarket.php?action=buy&ID={$r[']Buy[/url]] [[url='itemmarket.php?action=gift1&ID={$r[']Gift[/url]]"; } print "\n<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['itmname']}</td> <td>$price</td> <td>[[url='iteminfo.php?ID={$r[']Info[/url]] $link</td> </tr>"; } print "</table>"; } function itemm_remove() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT im.*,i.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid WHERE imID={$_GET['ID']} AND imADDER=$userid"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or you are not the owner. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); item_add($userid, $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}"); $db->query("INSERT INTO imremovelogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} removed a {$r['itmname']} from the item market.')"); print "Item removed from market! [url='itemmarket.php']> Back[/url]"; } function item_buy() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}",$c); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } item_add($userid, $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}"); $db->query("UPDATE users SET $curr=$curr-{$r['imPRICE']} where userid=$userid"); $db->query("UPDATE users SET $curr=$curr+{$r['imPRICE']} where userid={$r['imADDER']}"); if($curr=="money") { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for \$".number_format($r['imPRICE']).".",$c); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']}')"); print "You bought the {$r['itmname']} from the market for \$".number_format($r['imPRICE'])."."; } else { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for ".number_format($r['imPRICE'])." crystals.",$c); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for {$r['imPRICE']} crystals from user ID {$r['imADDER']}')"); print "You bought the {$r['itmname']} from the market for ".number_format($r['imPRICE'])." crystals."; } } function item_gift1() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } if($curr=="money") { print "Buying the [b]{$r['itmname']}[/b] for \$".number_format($r['imPRICE'])." as a gift... <form action='itemmarket.php?action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <input type='submit' value='Buy Item and Send Gift' /></form>"; } else { print "Buying the [b]{$r['itmname']}[/b] for ".number_format($r['imPRICE'])." crystals as a gift... <form action='itemmarket.php?action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <input type='submit' value='Buy Item and Send Gift' /></form>"; } } function item_gift2() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_POST['ID']}"); if(!$db->num_rows($q)) { print "Error, either this item does not exist, or it has already been bought. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $curr=$r['imCURRENCY']; if($r['imPRICE'] > $ir[$curr]) { print "Error, you do not have the funds to buy this item. [url='itemmarket.php']> Back[/url]"; $h->endpage(); exit; } item_add($_POST['user'], $r['imITEM'], 1); $i=($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_POST['ID']}"); $db->query("UPDATE users SET $curr=$curr-{$r['imPRICE']} where userid=$userid"); $db->query("UPDATE users SET $curr=$curr+{$r['imPRICE']} where userid={$r['imADDER']}"); if($curr=="money") { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for \$".number_format($r['imPRICE']).".",$c); event_add($_POST['user'], "[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought you a {$r['itmname']} from the item market as a gift.",$c); $u=$db->query("SELECT username FROM users WHERE userid={$_POST['user']}"); $uname=$db->fetch_single($u); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); print "You bought the {$r['itmname']} from the market for \$".number_format($r['imPRICE'])." and sent the gift to $uname."; } else { event_add($r['imADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['itmname']} item from the market for ".number_format($r['imPRICE'])." crystals.",$c); event_add($_POST['user'], "[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought you a {$r['itmname']} from the item market as a gift.",$c); $u=$db->query("SELECT username FROM users WHERE userid={$_POST['user']}"); $uname=$db->fetch_single($u); $db->query("INSERT INTO imbuylogs VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought a {$r['itmname']} from the item market for {$r['imPRICE']} crystals from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); print "You bought the {$r['itmname']} from the market for ".number_format($r['imPRICE'])." crystals and sent the gift to $uname."; } } $h->endpage(); ?> Quote
tittlemouse Posted March 2, 2008 Author Posted March 2, 2008 Re: itemmarket.php help that works a treat thanks +1 Quote
Godhand Posted March 3, 2008 Posted March 3, 2008 Re: itemmarket.php help find in item_remove replace with itemm_remove You can't have 2 functions as the same name. Quote
Floydian Posted March 3, 2008 Posted March 3, 2008 Re: itemmarket.php help On a side note, it's not correct to call a function before it's defined. All of mccodes is written with this error. You'll notice the switches always come before the function definitions. That is incorrect. The proper way to do it is to have the function definition before the switch. Like I said, this is a side note, and not directly related to a "solution" for the problem that was already fixed. Quote
Guest Anonymous Posted March 3, 2008 Posted March 3, 2008 Re: itemmarket.php help On a side note, it's not correct to call a function before it's defined. All of mccodes is written with this error. You'll notice the switches always come before the function definitions. That is incorrect. The proper way to do it is to have the function definition before the switch. Like I said, this is a side note, and not directly related to a "solution" for the problem that was already fixed. What is the difference between the switch scripted at the start instead of the end of the functions? as they seem to work the same. Quote
gangstas-conflict Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help whats the differnece in codes with v1? im getting this error Warning: include(globals.php) [function.include]: failed to open stream: No such file or directory in /home/gangstas/public_html/imarket.php on line 2 Warning: include() [function.include]: Failed opening 'globals.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/gangstas/public_html/imarket.php on line 2 Item Market Viewing all listings... Fatal error: Call to a member function query() on a non-object in /home/gangstas/public_html/imarket.php on line 31 Quote
Guest Anonymous Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help Compare them and you will soon find out. Quote
Floydian Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help RE: Zeon What's the difference in calling a function before or after it's defined? There are two things to consider: In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined such as shown in the two examples below. When a function is defined in a conditional manner such as the two examples shown. Its definition must be processed prior to being called. Secondly: It's considered a "best practice" to define functions before you call them, and to define them at the beginning of the code. You wouldn't want a professional Zend coder to look at some code and thing, dayum, who wrote this?? *wink wink* Quote
Godhand Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help whats the differnece in codes with v1? im getting this error Warning: include(globals.php) [function.include]: failed to open stream: No such file or directory in /home/gangstas/public_html/imarket.php on line 2 Warning: include() [function.include]: Failed opening 'globals.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/gangstas/public_html/imarket.php on line 2 Item Market Viewing all listings... Fatal error: Call to a member function query() on a non-object in /home/gangstas/public_html/imarket.php on line 31 Lmao get owned. I mean seriously. Search for the difference as it is an extremely easy fix. :-o how could someone screw that up..... anyone please tell me how any coder could mess that up..... Quote
gangstas-conflict Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help i never said i was a coder...im a noob trying to learn to code.... Quote
Guest Anonymous Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help You do not have to be a coder to replace a few lines. Quote
Godhand Posted March 11, 2008 Posted March 11, 2008 Re: itemmarket.php help i never said i was a coder...im a noob trying to learn to code.... He also said he didn't buy v2.. Check his posts they will tell you that much. Edit- here is a fast evidence for it. http://criminalexistence.com/ceforums/h ... 191#p80191 Or for the lazy No i didnt buy version 2? why is that the v2 code? Quote
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.