koopt alles inplaats van 1 item
ik hbe een koop scriptje gemaakt om armor te kopen maar inplaats dat hij 1 koop daarvan koopt hij alles
code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include("config.php");
include("ingelogd.php");
?>
<?php
$query = mysql_query("SELECT * FROM armor");
$result = mysql_num_rows($query);
while($armor = mysql_fetch_object($query))
{
$query2 = mysql_query("SELECT * FROM gebruikers WHERE id='$id'");
$result2 = mysql_num_rows($query2);
$player = mysql_fetch_object($query2);
?>
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
mysql_query("INSERT INTO inventory (id,itemname,def,grade,stars) VALUES (id='$player->id', itemname='$armor->name', def='$armor->def', grade='0' , stars='0')");
echo 'You bought a '. $armor->name;
}
?>
<br>
<form name='submit' method='post'>
<center><table border='1' width='90%'>
<tr>
<td width='20%'><b>Name</b></td>
<td width='15%'><b>Defense</b></td>
<td width='20%'><b>Required Rank</b></td>
<td width='15%'><b>Class</b></td>
<td width='20%'><b>Price</b></td>
</tr>
</table>
<table border='1' width='90%'>
<tr>
<td width='20%'><? echo $armor->name; ?></td>
<td width='15%'><? echo $armor->def; ?></td>
<td width='20%'><? echo $armor->reqlvl; ?></td>
<td width='15%'><? echo $armor->class; ?></td>
<td width='20%'><b>Gold: </b><? echo $armor->gold; ?><b> Silver: </b><? echo $armor->silver; ?></td>
<td width='5%'><input type='submit' value='Buy'></td>
</tr>
</table></center>
</form>
<br>
<?php
}
?>
include("config.php");
include("ingelogd.php");
?>
<?php
$query = mysql_query("SELECT * FROM armor");
$result = mysql_num_rows($query);
while($armor = mysql_fetch_object($query))
{
$query2 = mysql_query("SELECT * FROM gebruikers WHERE id='$id'");
$result2 = mysql_num_rows($query2);
$player = mysql_fetch_object($query2);
?>
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
mysql_query("INSERT INTO inventory (id,itemname,def,grade,stars) VALUES (id='$player->id', itemname='$armor->name', def='$armor->def', grade='0' , stars='0')");
echo 'You bought a '. $armor->name;
}
?>
<br>
<form name='submit' method='post'>
<center><table border='1' width='90%'>
<tr>
<td width='20%'><b>Name</b></td>
<td width='15%'><b>Defense</b></td>
<td width='20%'><b>Required Rank</b></td>
<td width='15%'><b>Class</b></td>
<td width='20%'><b>Price</b></td>
</tr>
</table>
<table border='1' width='90%'>
<tr>
<td width='20%'><? echo $armor->name; ?></td>
<td width='15%'><? echo $armor->def; ?></td>
<td width='20%'><? echo $armor->reqlvl; ?></td>
<td width='15%'><? echo $armor->class; ?></td>
<td width='20%'><b>Gold: </b><? echo $armor->gold; ?><b> Silver: </b><? echo $armor->silver; ?></td>
<td width='5%'><input type='submit' value='Buy'></td>
</tr>
</table></center>
</form>
<br>
<?php
}
?>
gebruik een hiddenid voor de armor en zorg dat die in de tabel wordt ingevoegd
en hoe werkt dat?
en dan in je if(isset($_POST['koop'])) eerst deze query :
$sql = "SELECT * FROM armor WHERE id = '".$_POST['hiddenid']."'";
$qry = mysql_query($sql);
$armor = mysql_fetch_array($qry);
en dan mag je je query hetzelfde houden als je nu hebt.
in je while een <input type='hidden' name='hiddenid' value='$sql = "SELECT * FROM armor WHERE id = '".$_POST['hiddenid']."'";
$qry = mysql_query($sql);
$armor = mysql_fetch_array($qry);
en dan mag je je query hetzelfde houden als je nu hebt.
dan krijg ik helemaal niks meer te zien