Ik ben bezig met het bouwen van een webshop.
Nu heb ik echter de volgende problemen:
als ik iets toevoeg krijg ik de volgende foutmeldingen:
Notice: Undefined index: mandje in E:\Internet\wwwroot\dullers\new4\webshop.php on line 49
Warning: Invalid argument supplied for foreach() in E:\Internet\wwwroot\dullers\new4\webshop.php on line 61
mijn code is:
index.php
---------------------------------------------------
---------------------------------------------------
webshop.php
---------------------------------------------------
---------------------------------------------------
Wat doe ik fout?
Zelf ben ik niet zo heel goed in PHP dus kan best zijn dat het een klein iets is.
Nu heb ik echter de volgende problemen:
als ik iets toevoeg krijg ik de volgende foutmeldingen:
Notice: Undefined index: mandje in E:\Internet\wwwroot\dullers\new4\webshop.php on line 49
Warning: Invalid argument supplied for foreach() in E:\Internet\wwwroot\dullers\new4\webshop.php on line 61
mijn code is:
index.php
---------------------------------------------------
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
52
53
54
55
56
57
58
59
60
61
62
| <?php // Sessie starten session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Index</title> </head> <body> <form name="form1" method="post" action="webshop.php"> <table width="950" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100">Merk</td> <td width="100">Product</td> <td width="100">Prijs</td> <td width="100">Inhoud</td> <td width="230">Omschrijving</td> <td width="100">Foto</td> <td width="200"> </td> </tr> </table> <?php $host = "localhost"; // Host $user = "root"; // MySQL gebruiker $pass = ""; // MySQL wachtwoord $db = "dullers"; // MySQL database // Verbinding tot stand brengen mysql_connect($host,$user,$pass) or die("Verbinding met database mislukt"); mysql_select_db($db) or die("Kan de database niet vinden"); $artikelen_sql = "SELECT * FROM artikelen"; $artikelen_result = mysql_query($artikelen_sql); while ($artikelen = mysql_fetch_array($artikelen_result)) { ?> <table width="950" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"> <tr valign="top"> <td width="100"><?php echo $artikelen['Merk'] ?></td> <td width="100"><?php echo $artikelen['Product'] ?></td> <td width="100"><?php echo $artikelen['Prijs'] ?></td> <td width="100"><?php echo $artikelen['Inhoud'] ?></td> <td width="230"><?php echo nl2br($artikelen['Omschrijving']) ?></td> <td width="100">[img]"images/<?php[/img]"></td> <td width="200">Aantal <input name="aantal" type="text" size="2"> <input name="product" type="hidden" value="<?php echo ($artikelen['Merk'] . " " . $artikelen['Product']);?>"> <input name="actie" type="hidden" value="toevoegen"> <input name="prijs" type="hidden" value="<?php echo $artikelen['Prijs'];?>"> <input type="submit" name="Submit" value="Toevoegen"> </td> </tr> </table><br> <?php } mysql_close(); ?> </form> </body> </html> |
---------------------------------------------------
webshop.php
---------------------------------------------------
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
| <?php // Sessie starten session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Webshop</title> </head> <body> <table width="950" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="75"><div align="center">Aantal</div></td> <td>Product</td> <td width="100"><div align="center">Prijs</div></td> <td width="100"><div align="center"></div></td> </tr> </table> <? // Kijken of de verbinding met de database er nog is if (!@mysql_select_db("dullers", @mysql_connect("localhost", "root", ""))) { echo "er kon geen database connectie gemaakt worden."; exit(); } # De functies // Product toevoegen function addProduct ($piProductId,$piAantal) { if ($piAantal != 0) { if (!isset($_SESSION['mandje'][$piProductId])) { $_SESSION['mandje'][$piProductId] = 0; } $_SESSION['mandje'][$piProductId] += $piAantal; } } // Product verwijderen function deleteProduct ($piProductId) { if (isset($_SESSION['mandje'][$piProductId])){ $_SESSION['mandje'][$piProductId] += $piAantal; unset($_SESSION['mandje'][$piProductId]); } } // Producten uitlezen function getProducts () { if (count($_SESSION['mandje']) > 0) RETURN $_SESSION['mandje']; } // Product toevoegen if(isset($_POST["actie"]) AND $_POST["actie"] == "toevoegen") { $aantal = $_POST['aantal']; $product = $_POST['product']; $prijs = $_POST['prijs']; addProduct($product,$aantal); $aProducts = getProducts(); foreach ($aProducts as $iProductId => $iAantal) { ?> <table width="950" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"> <tr> <td width="75"><div align="center"><?php echo $iAantal ?></div></td> <td><?php echo $iProductId ?></td> <td width="100"><div align="center"><?php $prijstotaalproduct = $iAantal * $prijs; echo $prijstotaalproduct; ?></div></td> <td width="100"><div align="center">verwijderen</div></td> </tr> </table> <?php } } ?> </body> </html> |
---------------------------------------------------
Wat doe ik fout?
Zelf ben ik niet zo heel goed in PHP dus kan best zijn dat het een klein iets is.