Deanznet Posted November 28, 2007 Share Posted November 28, 2007 Hey i need to get the name="namehere" from the database. I tried name="$get_info['item_name']" But didn't work. Part of the code: print '<table width=200 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)){ print "<tr>"; print "\t<td><font face=arial size=1/>"; print '<input type="checkbox" name="namehere" />'.$get_info['item_name'].'</font></td>'; print "</tr>"; Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Show us your query. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 28, 2007 Author Share Posted November 28, 2007 <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ( (!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; // Retrieve all the data from the "example" table $result = mysql_query("SELECT * FROM phpbb_adr_shops_items WHERE item_owner_id = '1' ") or die(mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print '<table width=200 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)){ print "<tr>"; print "\t<td><font face=arial size=1/>"; print '<input type="checkbox" name="namehere" />'.$get_info['item_name']. $get_info['item_id'].'</font></td>'; print "</tr>"; } print "</table></form>"; } else { echo('You are a guest'); } ?> Thats all i got so far.. This is for a store when someone post i need it to update the table the item is in and change its owner id to the user id that the user is loged in with Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Your confusing me. The problem you just posted is completely different than what you posted in the original post. From your fist post, it sounds like this is the chunk of code your having problems with <?php $result = mysql_query("SELECT * FROM phpbb_adr_shops_items WHERE item_owner_id = '1' ") or die(mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print '<table width=200 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)){ print "<tr>"; print "\t<td><font face=arial size=1/>"; print '<input type="checkbox" name="namehere" />'.$get_info['item_name']. $get_info['item_id'].'</font></td>'; print "</tr>"; } ?> Tell us exactly what the problem is, and what you would like to happen. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 28, 2007 Author Share Posted November 28, 2007 Okay Sorry for the confusion. Basically I have 1 php file witch is the store. The code i is posted above. Right now all that dose is get the items from the database and puts a check box next to them. The items are listed in the database such as item name, owner id, picture, desc item name, owner id, picture, desc item name, owner id, picture, desc I need to figure out how to make a list box at the end that has Buy or Sell and a submit button. When a selects buy and hit submit and he has 1 or more item checked it will update those items in each table and put The The users username where the Owner id is. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Okay, here is some code to give you a start. <?php //check if they submitted the form if (isset($_POST['submit'])){ if ($_POST['action'] == 'buy'){ echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach ($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_adr_shops_items WHERE item_owner_id = '1' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=200 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_id']}' />" .$get_info['item_name']. $get_info['item_id']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; ?> Let me know if you have any problems with it. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 28, 2007 Author Share Posted November 28, 2007 That works great but im having trouble with my mysql query for the buying part. mysql_query("UPDATE phpbb_adr_shops_items SET item_owner_id = '$user_id' WHERE item_name = '$item_name"); mysql_query($query); echo "Item Bought<br>"; } } else { echo "They chose 'sell'"; } The problem is it dosent update the database at all. if i put in the item name such as item_name = 'Myname' It will update it. Also when they buy how do i make it check if this person has enough cash and if they do they will subtract their the price from their cash. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 if i put in the item name such as item_name = 'Myname' It will update it. Well...that tells us that your variable $item_name is empty or not set. Post your entire updated code. Also when they buy how do i make it check if this person has enough cash and if they do they will subtract their the price from their cash. This is very basic MySQL...you should go google for some tutorials. <?php //select the users money $query = mysql_query("SELECT money FROM users WHERE userID='$userID'")or die(mysql_error()); $money = mysql_fetch_assoc($query); //Check if they have enough if ($money['money'] > $price){ //they have enough, now do a query to subtract their money $subtract = mysql_query("UPDATE users SET money=money-$price WHERE userID='$userID'") or die(mysql_error()); } else { //they don't have enough money, give them an error... } ?> Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ( (!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; //check if they submitted the form if (isset($_POST['submit'])){ if ($_POST['action'] == 'buy'){ echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach ($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query mysql_query("UPDATE phpbb_adr_shops_items SET item_owner_id = '1' WHERE item_name = '$item_name"); mysql_query($query); echo "Item Bought<br>"; } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_adr_shops_items WHERE item_owner_id = '1' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "<br>There are $num_rows cards left in the store.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=200 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_name']}' />" .$get_info['item_name']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; } else { echo('You are a guest'); } ?> Thats my Whole Update code Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 I don't see where you getting the variable $item_name...where is it SUPPOSED to be coming from? Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 Suppose to grab it from the database well it pulls the item_name from database $result = mysql_query("SELECT * FROM phpbb_adr_shops_items WHERE item_owner_id = '1' ")or die(mysql_error()); and when they hit submit its suppose to get the item_name that was checked next to it. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Okay, change you query to this mysql_query("UPDATE phpbb_adr_shops_items SET item_owner_id = '1' WHERE item_name = '$itemID'"); That should work, let me know if it does or doesn't. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 Works man! Im trying to get it the money thing to work. <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ( (!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; //select the users money $query = mysql_query("SELECT user_points FROM phpbb_users WHERE user_id='$user_id'")or die(mysql_error()); $user_points = mysql_fetch_assoc($query); //check if they submitted the form if (isset($_POST['submit'])){ if ($_POST['action'] == 'buy'){ echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach ($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query mysql_query("UPDATE phpbb_trading SET item_in_shop = '0', itemid = '$user_id' WHERE item_name = '$itemID'"); mysql_query($query); echo "Item Bought<br>"; //Check if they have enough if ($user_points['user_points'] > $item_price){ //they have enough, now do a query to subtract their money $subtract = mysql_query("UPDATE users SET user_points=user_points-$item_price WHERE itemid='$user_id'") or die(mysql_error()); } else { //they don't have enough money, give them an error... echo "Not Enought Boomies'"; } } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_trading WHERE item_in_shop = '1'and itemid = '0' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "<br>There are $num_rows cards left in the store.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=500 height= 500 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_name']}' />" .$get_info['item_name'].'<br><td>'.$get_info['item_price'].'<br>'.Boomies.'<br><td>'.$get_info['item_desc']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; } else { echo('You are a guest'); } ?> When i hit buy it says Bronze Trading Test Item Bought 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 'WHERE itemid='3'' at line 1 Just so you know The user cash is called user_points the item price is item_price Those are the tables they are in the user_points are located in the phpbb_user table and the item_price are located in phpbb_trading Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Okay, try this and post anything you get. Look through the queries and make sure I got all the row names right and everything <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ( (!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; //select the users money $query = mysql_query("SELECT user_points FROM phpbb_users WHERE user_id='$user_id'")or die(mysql_error()); $user_points = mysql_fetch_assoc($query); //check if they submitted the form if (isset($_POST['submit'])){ if ($_POST['action'] == 'buy'){ echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach ($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query mysql_query("UPDATE phpbb_trading SET item_in_shop = '0', itemid = '$user_id' WHERE item_name = '$itemID'"); mysql_query($query)or die(mysql_error()); echo "Item Bought<br>"; //get the items price $get_price = mysql_query("SELECT item_price FROM phpbb_trading WHERE item_name='$itemID'")or die(mysql_error()); $price = mysql_fetch_assoc($get_price); //Check if they have enough if ($user_points['user_points'] > $price['item_price']){ //they have enough, now do a query to subtract their money $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE itemid='$user_id'"; $subtract_final = mysql_query($subtract)or die('ERROR: '.mysql_error().' with query<br>'.$subract); } else { //they don't have enough money, give them an error... echo "Not Enought Boomies'"; } } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_trading WHERE item_in_shop = '1'and itemid = '0' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "<br>There are $num_rows cards left in the store.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=500 height= 500 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_name']}' />" .$get_info['item_name'].'<br><td>'.$get_info['item_price'].'<br>'.Boomies.'<br><td>'.$get_info['item_desc']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; } else { echo('You are a guest'); } ?> Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 These are the items that were selected [they chose 'buy'] Gold Test 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 'Resource id #23' at line 1 It dose run this Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Okay, try this... <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ( (!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; //select the users money $query = mysql_query("SELECT user_points FROM phpbb_users WHERE user_id='$user_id'")or die(mysql_error()); $user_points = mysql_fetch_assoc($query); //check if they submitted the form if (isset($_POST['submit'])){ if ($_POST['action'] == 'buy'){ echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach ($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query $update_q = "UPDATE phpbb_trading SET item_in_shop = '0', itemid = '$user_id' WHERE item_name = '$itemID'"; $update_q_final = mysql_query($update_q)or die(mysql_error().'With Query<p>'.$update_q); echo "Item Bought<br>"; //get the items price $get_price = mysql_query("SELECT item_price FROM phpbb_trading WHERE item_name='$itemID'")or die(mysql_error()); $price = mysql_fetch_assoc($get_price); //Check if they have enough if ($user_points['user_points'] > $price['item_price']){ //they have enough, now do a query to subtract their money $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE itemid='$user_id'"; $subtract_final = mysql_query($subtract)or die('ERROR: '.mysql_error().' with query<br>'.$subract); } else { //they don't have enough money, give them an error... echo "Not Enought Boomies'"; } } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_trading WHERE item_in_shop = '1'and itemid = '0' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "<br>There are $num_rows cards left in the store.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=500 height= 500 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_name']}' />" .$get_info['item_name'].'<br><td>'.$get_info['item_price'].'<br>'.Boomies.'<br><td>'.$get_info['item_desc']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; } else { echo('You are a guest'); } ?> Where the heck is "Gold Test" coming from? Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 These are the items that were selected [they chose 'buy'] Gold Test Item Bought ERROR: Unknown column 'itemid' in 'where clause' with query Gold Test is just an Item in the Database thats the name.. When someone buys it says what item they bought such as Gold test Item Bought.. Ya but i get that Also when i go and try to buy something than more points than i have it says i dont have enough points but it goes ahead and buys it anyways Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 29, 2007 Share Posted November 29, 2007 These are the items that were selected [they chose 'buy'] Gold Test Item Bought ERROR: Unknown column 'itemid' in 'where clause' with query Gold Test is just an Item in the Database thats the name.. When someone buys it says what item they bought such as Gold test Item Bought.. Ya but i get that Also when i go and try to buy something than more points than i have it says i dont have enough points but it goes ahead and buys it anyways show us the structure of your db. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Okay, look at this query $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE itemid='$user_id'"; It's saying the col "itemid" doesn't exist. So you need to change that to whatever the actual column name is. <?php define('IN_PHPBB', true); define('IN_CASHMOD', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if (!$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if ($userdata['session_logged_in']) { // Who is looking at this page ? $user_id = $userdata['user_id']; if ((!( isset($HTTP_POST_VARS[post_USERS_URL]) || isset($HTTP_GET_VARS[post_USERS_URL]))) || ( empty($HTTP_POST_VARS[post_USERS_URL]) && empty($HTTP_GET_VARS[post_USERS_URL]))) { $view_userdata = $userdata; } else { $view_userdata = get_userdata(intval($HTTP_GET_VARS[post_USERS_URL])); } $searchid = $view_userdata['user_id']; $points = $userdata['user_points']; $posts = $userdata['user_posts']; //select the users money $query = mysql_query("SELECT user_points FROM phpbb_users WHERE user_id='$user_id'")or die(mysql_error()); $user_points = mysql_fetch_assoc($query); //check if they submitted the form if (isset($_POST['submit'])) { if ($_POST['action'] == 'buy') { echo "These are the items that were selected [they chose 'buy']<br>"; //Loop through the selected items foreach($_POST['selected'] as $itemID){ echo $itemID.'<br>'; //this is where you would do your query $update_q = "UPDATE phpbb_trading SET item_in_shop = '0', itemid = '$user_id' WHERE item_name = '$itemID'"; $update_q_final = mysql_query($update_q)or die(mysql_error().'With Query<p>'.$update_q); echo "Item Bought<br>"; //get the items price $get_price = mysql_query("SELECT item_price FROM phpbb_trading WHERE item_name='$itemID'") or die(mysql_error()); $price = mysql_fetch_assoc($get_price); //Check if they have enough if ($user_points['user_points'] > $price['item_price']) { echo "<p><b>Price:</b> - {$price['item_price']}<p>"; //they have enough, now do a query to subtract their money $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE itemid='$user_id'"; $subtract_final = mysql_query($subtract)or die('ERROR: '.mysql_error().' with query<br>'.$subtract); } else { //they don't have enough money, give them an error... echo "Not Enought Boomies'"; } } } else { echo "They chose 'sell'"; } } $result = mysql_query("SELECT * FROM phpbb_trading WHERE item_in_shop = '1'and itemid = '0' ")or die(mysql_error()); $num_rows = mysql_num_rows($result); print "<br>There are $num_rows cards left in the store.<P>"; print "<form action='{$_SERVER['PHP_SELF']}' method='post'>"; print '<table width=500 height= 500 border=1>'."\n"; while ($get_info = mysql_fetch_assoc($result)) { print "<tr>"; print "\t<td><font face=arial size=1/>"; print "<input type='checkbox' name='selected[]' value='{$get_info['item_name']}' />" .$get_info['item_name'].'<br><td>'.$get_info['item_price'].'<br>'.Boomies.'<br><td>'.$get_info['item_desc']."</font></td>"; print "</tr>"; } echo '<select name="action">' .'<option value="buy">Buy</option>' .'<option value="sell">Sell</option>' .'</select><p>'; echo '<input type="submit" name="submit">'; echo '</form>'; } else { echo('You are a guest'); } ?> Okay, try buying an item and see what it does/says. This is really hard trying to fix this when I have a small amount of information to work with such as database structure and all that. It's okay though, we will just have to take it one thing at a time until we figure it all out Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 29, 2007 Share Posted November 29, 2007 This is really hard trying to fix this when I have a small amount of information to work with such as database structure and all that. It's okay though, we will just have to take it one thing at a time until we figure it all out The exact reason why I asked for the structure. LOL Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 These are the items that were selected [they chose 'buy'] Gold Test Item Bought Price: - 5093 ERROR: Unknown column 'itemid' in 'where clause' with query UPDATE phpbb_users SET user_points=user_points-5093 WHERE itemid='3' Same thing Heres the Db but itemid dose exist.. -- phpMyAdmin SQL Dump -- version 2.7.0-pl2 -- http://www.phpmyadmin.net -- -- Host: 10.0.11.199 -- Generation Time: Nov 28, 2007 at 09:10 PM -- Server version: 4.0.27 -- PHP Version: 4.4.4 -- -- Database: `Boomboard` -- -- -------------------------------------------------------- -- -- Table structure for table `phpbb_trading` -- CREATE TABLE `phpbb_trading` ( ` item_id` int( NOT NULL default '0', `itemid` int( NOT NULL default '0', `item_price` int( NOT NULL default '0', `item_quality` varchar(225) NOT NULL default '', `item_name` varchar(255) NOT NULL default '', `item_desc` varchar(255) NOT NULL default '', `item_in_shop` tinyint(1) NOT NULL default '0' ) TYPE=MyISAM; -- -- Dumping data for table `phpbb_trading` -- INSERT INTO `phpbb_trading` VALUES (1, 3, 5093, 'Bronze', 'Bronze Trading Test', 'Cool Card To Have', 0); INSERT INTO `phpbb_trading` VALUES (2, 3, 2147483647, 'Silver', 'Silver Card Test', 'Another Cool Card', 0); INSERT INTO `phpbb_trading` VALUES (3, 3, 5093, 'Gold', 'Gold Test', 'Gold test', 0); INSERT INTO `phpbb_trading` VALUES (4, 0, 5093, 'Silver', 'Silver Card Test 2', 'This Is just a test', 1); Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 How about the phpbb_users table? Does itemid exist in there? We are trying to update the USERS points...so I would assume you had a field called "userid" or something. You also need to tell me what variable in the script holds their ID. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 $user_id holds their id - that works fine Thats located in the phpbb_user table with the user_points itemid is only in the phpbb_trading table. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 I'm thinking this query $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE itemid='$user_id'"; Should be changed to this $subtract = "UPDATE users SET user_points=user_points-{$price['item_price']} WHERE id='$user_id'"; Do you see what I'm saying? Where "id" is in the query is where you need to change it to whatever field the users ID is stored in the phpbb_users table. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 29, 2007 Author Share Posted November 29, 2007 OH! so its prob user_id=$user_id'"; I gotta try it when i get to the house 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.