ghqwerty Posted October 8, 2008 Share Posted October 8, 2008 ok so for some reason my code never gets round to executing my if(isset(... code and i cant see why ?? could someone please spot it as i cant see anythign wrong with it <?php if(isset($_post['buy'])){ $itemname2 = $_post['buy_items']; $itemname = implode(",", $itemname2); $costofitem = mysql_query("select sum(moneybad) from itemstats where item in($itemname)") or die (mysql_error()); $costofitem2 = mysql_fetch_array($costofitem); mysql_query("update members set money = money - '".$costofitem2['moneybad']."' where id = '".$_SESSION['id']."'") or die ("item can not be bought " . mysql_error()); $name = mysql_query("select username from members where id = '".$_SESSION['id']."'") or die (mysql_error()); $whatname = mysql_fetch_arry($name); $user = $whatname['username']; mysql_query("insert into items(item, userid, user) values('".$item."', ".$_SESSION['id'].", '".$user."' ") or die (mysql_error()); echo "you bought the ".$_POST['buy']." for $".$costofitem2['moneybad'].""; } $items = mysql_query("select item, moneybad from itemstats where item != 'scout tactical' and item != 'spas 12'") or die(mysql_error()); while($itemresults = mysql_fetch_array($items)){ $item = $itemresults['item']; $cost = $itemresults['moneybad']; echo " <tr> <td> ".$item." </td> <td> ".$cost." </td> <td> <form action=\"buyitems.php\" method='post'> <input type='checkbox' name='buy_items[]' value='".$item."'> </td> </tr> "; } echo " <tr> <td colspan='3'> <input type='submit' id='buy' value='buy!' </form> </td> </tr> </table>"; ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 It should be $_POST, not $_post. Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 8, 2008 Author Share Posted October 8, 2008 still aint worked Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 Add: print_r($_POST); Before the if. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 9, 2008 Share Posted October 9, 2008 Also place this at the top of your page: error_reporting(E_ALL); ini_set("display_errors", "1"); Make sure all field names are correct and that the form is being submitted properly. Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 9, 2008 Author Share Posted October 9, 2008 Array ( [buy_items] => Array ( [0] => ak47 [1] => p90 [2] => revolver ) ) is what i get from the print_r and projectfear that doesnt change or show anythign Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 9, 2008 Share Posted October 9, 2008 You should be doing if(isset($_POST['buy_items'])), because that's apparently what your POST array has. Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 9, 2008 Author Share Posted October 9, 2008 hmm i found out the problem its because i had id-'buy' not name='buy' but now i keep getting Unknown column 'ak47' in 'where clause' im guessing that is reffering to this line $costofitem = mysql_query("select sum(moneybad) from itemstats where item in($itemname)") or die (mysql_error()); and $itemname is $itemname2 = $_POST['buy_items']; $itemname = implode(",", $itemname2); so i cant see why it isnt working i think it is part of the implode as it isnt showing the whole array on there Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 9, 2008 Share Posted October 9, 2008 Each item in the $itemname would need ' ' around it. You might be able to get away with: <?php $itemnames = array('ak47', 'revolver', 'm-16'); //just for my testing $itemnames = array_map(create_function('$a', 'return "\'$a\'";'), $itemnames); $itemname = implode(',', $itemnames); echo $itemname; ?> Tested and works, btw. 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.