Hi i'm making a new website based on PHP. I bumped on a problem now...
The problem is that I have a loop where i get all records out of my sql database and get them into a form. Every record has a differend form with a button to. Every button then has a unique ID.
Now i tried everyting i could think of to get the value out of a button when a button is clicked. But nothing worked... here is the part of the code where everything is for the form and the POST.
while($record = mysql_fetch_object($result)){
$id = $record->id;
echo"<form action='home.php' method='post'>";
echo"<b>name:</b>".$record->name." <b>Price: </b>".$record->price."";
echo'<input type="hidden" name="id" value='.$id.'>';
echo"<input type='submit' value='Buy' /><br />";
echo"</form>";
}
if($_POST) {
$ID = intval($_POST['id']);
$query1 = "SELECT price FROM items WHERE id = ".$ID."";
$result1 = mysql_query($query1);
list($cost) = mysql_fetch_row($result1);
$gold = getStat('gc',$userID);
if($gold > $cost) {
setStat('gc',$userID,($gold - $cost));
$queryw = "INSERT INTO users_inventory(item_id,user_id, quantity) VALUES ('".$ID."','".$userID."','1')";
$resultw = mysql_query($queryw);
} else {
echo"You can't afford this weapons.";
}
}
The only thing that doesn't seem to work is this part
$ID = intval($_POST['id']);
is always gives me this error:
Notice: Undefined index: id in shop.php on line 26
Please help me out here i have no idea what to do from here on...