marvin Posted October 29, 2011 Share Posted October 29, 2011 is it possible to make it so when people try to send items to each other the receiver needs to manually accept it instead of it just being accepted? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 29, 2011 Share Posted October 29, 2011 Anything's possible :) I'm guessing a new table would have to be created, and then when someone sends an item it gets put into that table instead of the other users inventory. Then once the receiver accepts it, it gets removed from that table and into their inventory. So like this User1 sends User2 a gun It gets inserted into the table, lets say 'itemsend' and an event gets created telling them to accept it. A page would probably have to be created where users can see their goods that have to be accepted User2 accepts the goods and it gets removed from 'itemsend' and inserted into User2's inventory Quote Link to comment Share on other sites More sharing options...
marvin Posted October 29, 2011 Author Share Posted October 29, 2011 Can someone make that for me , I would be willing to pay $10 for it. Its beyond my capabilities. Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 29, 2011 Share Posted October 29, 2011 Give it a go, and I am sure people will be more then willing to help with any errors. Here is a place to start -> basic new table to store the item sent, who is sending it, the amount, and the receiver. -> send event asking if they want the item. -> basic PHP page that adds item back into one of the two users inventory's. Quote Link to comment Share on other sites More sharing options...
Pitch Black Posted October 30, 2011 Share Posted October 30, 2011 (edited) You could keep it to 1 table gurpreet: Add 2 columns `pending` and `pending_amt` to inventory, if an item is sent fill pending with the user id it is being sent to, otherwise keep it clear. Edited October 30, 2011 by Pitch Black Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 (edited) I've done what Pitch Black suggested and created 2 new columns in the inventory table - pending, pending_amount. Here's what I got so far, it works fine for the index(), but the accept is bugged. 1) It doesn't accept the correct item, it accepts 1 item above. 2) It doesn't add the item to the receiver (me)'s inventory. Same with the decline. If someone could work on it and finish it, it would be great. P.S - Thanks very much Pitch Black for your help on IRC and putting up with me! I came across a lot of bugs when making this and Pitch Black helped me fix them all! itemsend.php: <?php include "globals.php"; //itemsend $_GET['ID'] = abs((int) $_GET['ID']); $_GET['qty'] = abs((int) $_GET['qty']); if($_GET['qty'] && $_GET['user']) { $id=$db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid LIMIT 1"); if($db->num_rows($id)==0) { print "Invalid item ID"; } else { $r=$db->fetch_row($id); $m=$db->query("SELECT * FROM users WHERE userid={$_GET['user']} LIMIT 1"); if($_GET['qty'] > $r['inv_qty']) { print "You are trying to send more than you have!"; } else if( $_GET['qty'] <= 0) { print "You haven't entered a valid amount to send."; } else if($db->num_rows($m) == 0) { print "You are trying to send to an invalid user!"; } else { $rm=$db->fetch_row($m); //are we sending it all print "You sent {$_GET['qty']} {$r['itmname']}(s) to {$rm['username']}. However, they must accept this item before they can use it."; event_add($_GET['user'],"You received {$_GET['qty']} {$r['itmname']}(s) from <a href='viewuser.php?u=$userid'>{$ir['username']}</a>. Click <a href='acceptitems.php'>Here</a> to accept this item and view another items you have yet to accept.",$c); $db->query("INSERT INTO itemxferlogs VALUES('',$userid,{$_GET['user']},{$r['itmid']},{$_GET['qty']},unix_timestamp(), '{$ir['lastip']}', '{$rm['lastip']}')"); $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}')"); } } } else if($_GET['ID']) { $id=$db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid LIMIT 1"); if($db->num_rows($id)==0) { print "Invalid item ID"; } else { $r=$db->fetch_row($id); print "<b>Enter who you want to send {$r['itmname']} to and how many you want to send. You have {$r['inv_qty']} to send.</b><br /> <form action='itemsend.php' method='get'> <input type='hidden' name='ID' value='{$_GET['ID']}' />User ID: <input type='text' name='user' value='' /><br /> Quantity: <input type='text' name='qty' value='' /><br /> <input type='submit' value='Send Items (no prompt so be sure!)' /></form>"; } } else { print "Invalid use of file."; } $h->endpage(); ?> acceptitems.php <?php include "globals.php"; $_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : ""; switch($_GET['action']) { case "accept": accept(); break; case "decline": decline(); break; default: index(); break; } function index() { global $db,$ir,$c,$userid,$h; $q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid FROM inventory inv LEFT JOIN users u ON inv.pending=u.userid LEFT JOIN items i ON i.itmid=inv.inv_itemid WHERE inv.pending={$ir['userid']}"); $num = mysql_num_rows($q); echo "<h3>Accept Items</h3><br><br> The items that you have yet to accept are listed below.<br>"; if($num==0) { echo "You do not have any items to accept.<br>> <a href='index.php'>Go home</a>"; } else { echo "<table width='100%' border='1'> <tr> <th>From</th> <th>Item Name</th> <th>Quantity</th> <th>Time</th> <th>Accept</th> <th>Decline</th> </tr>"; while($item = mysql_fetch_array($q)) { $sent=date('F j, Y, g:i:s a',$item['timeSENT']); echo "<tr> <td>{$item['username']}</td> <td>{$item['itmname']}</td> <td>{$item['pending_amount']}</td> <td>$sent</td> <td><a href='acceptitems.php?action=accept'>Accept</a></td> <td><a href='acceptitems.php?action=decline'>Decline</a></td>"; } echo "</table>"; } } function accept() { global $db,$ir,$c,$userid,$h; $q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid FROM inventory inv LEFT JOIN users u ON inv.pending=u.userid LEFT JOIN items i ON i.itmid=inv.inv_itemid WHERE inv.pending={$ir['userid']}"); $num = mysql_num_rows($q); $item = mysql_fetch_array($q); if($num==0) { die("Either this is not your item to accept or this has already been accepted."); } echo "You have <span style=color:green;>accepted</span> the item <span style=color:green;>{$item['itmname']}</span> from <span style=color:green;>{$item['username']}</span>. Click <a href='acceptitems.php'>Here</a> to go back to accept more items.<br>"; item_add($ir['userid'],$item['inv_itemid'],$item['pending_amount']); mysql_query("DELETE FROM inventory WHERE inv_id={$item['inv_id']}"); } function decline() { global $db,$ir,$c,$userid,$h; $q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid FROM inventory inv LEFT JOIN users u ON inv.pending=u.userid LEFT JOIN items i ON i.itmid=inv.inv_itemid WHERE inv.pending={$ir['userid']}"); $num = mysql_num_rows($q); $item = mysql_fetch_array($q); if($num==0) { die("Either this is not your item to decline or this has already been declined and sent back to the sender."); } echo "You have <span style=color:red;>declined</span> the item <span style=color:red;>{$item['itmname']}</span> from <span style=color:red;>{$item['username']}</span>. Click <a href='acceptitems.php'>Here</a> to go back to accept or decline more items.<br>"; //Needs 2 working queries, 1 to add and 1 to remove } ?> Edited October 30, 2011 by gurpreet Quote Link to comment Share on other sites More sharing options...
marvin Posted October 30, 2011 Author Share Posted October 30, 2011 ok. when I try to send the item it says QUERY ERROR: Unknown column 'first' in 'where clause' Query was SELECT * FROM users WHERE userid=first LIMIT 1 and "first" is the username of the receiver. Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 You need to enter the user ID, not the username. As you can see it says "where USERID = xx" Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 30, 2011 Share Posted October 30, 2011 There are item_add(), and item_remove() functions for mccodes. Use them. ;) Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 There are item_add(), and item_remove() functions for mccodes. Use them. ;) Heh I did, but they messed up. If you're referring to the UPDATE inventory part in itemsend, then it's necessary. The pending and pending_amount columns are NULL, but when someone sends an item, the null fields get filled. Then once accepted, the original record deletes but the item_add doesn't work (the accept and decline functions are buggeed and I couldn't fix them) Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 30, 2011 Share Posted October 30, 2011 Heh I did, but they messed up. If you're referring to the UPDATE inventory part in itemsend, then it's necessary. The pending and pending_amount columns are NULL, but when someone sends an item, the null fields get filled. Then once accepted, the original record deletes but the item_add doesn't work (the accept and decline functions are buggeed and I couldn't fix them) I looked at the comment that says you need to queries (decline() 2nd page), but anyway why don't your item functions work? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 Ah ok I'm not too sure to be honest, they have the correct format and the values are all correct if i echo each one out. Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 Ah ok I'm not too sure to be honest, they have the correct format and the values are all correct if i echo each one out. Quote Link to comment Share on other sites More sharing options...
marvin Posted October 30, 2011 Author Share Posted October 30, 2011 You need to enter the user ID, not the username. As you can see it says "where USERID = xx" If the persons name is "john" then when it asks me who to send item to, I put john. What else would I put? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 You would put John's ID. This can be changed but it would take a while Quote Link to comment Share on other sites More sharing options...
marvin Posted October 30, 2011 Author Share Posted October 30, 2011 (edited) You would put John's ID. This can be changed but it would take a while I get it. Ok so here is the error after I sent it. You sent Apple to first. However, they must accept this item before they can use it.QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 1 Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1') Edited October 30, 2011 by marvin Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 30, 2011 Share Posted October 30, 2011 Change: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}')"); To: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']})"); Quote Link to comment Share on other sites More sharing options...
marvin Posted October 30, 2011 Author Share Posted October 30, 2011 Change: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}')"); To: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']})"); You sent 1 Apple to first. However, they must accept this item before they can use it.QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1) Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 31, 2011 Share Posted October 31, 2011 Oops sorry missed that bracket. Try this: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}"); Quote Link to comment Share on other sites More sharing options...
marvin Posted November 1, 2011 Author Share Posted November 1, 2011 Oops sorry missed that bracket. Try this: $db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}"); You sent 1 Apple to first. However, they must accept this item before they can use it.QUERY ERROR: Unknown column 'pending' in 'field list' Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1 Quote Link to comment Share on other sites More sharing options...
gurpreet Posted November 1, 2011 Share Posted November 1, 2011 That means you haven't run the queries to add them. Run these Alter table inventory add pending int(11) Alter table inventory add pending_amount int(11) Quote Link to comment Share on other sites More sharing options...
gurpreet Posted November 2, 2011 Share Posted November 2, 2011 I tried posting yesterday, seems T-Mobile's internet is total crap. Try running these queries: ALTER TABLE inventory ADD pending int(11); ALTER TABLE inventory ADD pending_amount int(11); Quote Link to comment Share on other sites More sharing options...
marvin Posted November 2, 2011 Author Share Posted November 2, 2011 hmmm how do I do that bro, do I login to phpmyadmin? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted November 2, 2011 Share Posted November 2, 2011 Yep, log into PHPMyAdmin, and select the SQL tab, then just copy and paste those queries Quote Link to comment Share on other sites More sharing options...
marvin Posted November 3, 2011 Author Share Posted November 3, 2011 ok now it looks good. I see in the events of the of the person receiving they have the option to accept. Now how do they reject it and what happens if they dont ever accept they just leave it? Does the item stay in limbo? 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.