Jump to content

buy items not getting to if(isset(...


ghqwerty

Recommended Posts

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>";

						?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.