Mijn formulier (bestellijst) werkt niet meer
default poort van Mysql is trouwens 3306
Eerlijk gezegd zie ik door de bomen het bos niet meer. Kan iemand mij vertellen hoe het script (klein test script) er nu uit zou moeten zien?
Quote:
echter ik heb er weer andere foutmeldingen voor terug.
Kom maar op! ;-)
vroeger was het : mysql_query($sql, $connection);
waarbij de 2e parameter optioneel was en in 99% van de gevallen weggelaten werd (alleen als je met verschillende databases verbond)
nu is het mysqli_query($connection, $sql);
en is de $connection verplicht.
---
Verder kun je nog een hoop winnen met prepared statements.
niet alleen gaat het escapen dan automatisch, maar ik zie ook dat je de update query in een loop hebt staan.
Dat zou dan 1x preparen worden met steeds nieuwe parameters afschieten en uitvoeren
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$link = new mysqli('127.0.0.1','root','','test', 3306);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
mysqli_close($link);
?>
error_reporting(E_ALL);
ini_set('display_errors', true);
$link = new mysqli('127.0.0.1','root','','test', 3306);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
mysqli_close($link);
?>
Foutmelding:
Warning: mysqli::__construct(): (HY000/2002): Connection refused in /volume1/web/test2.php on line 6 Success: A proper connection to MySQL was made! The my_db database is great. Warning: mysqli_close(): Couldn't fetch mysqli in /volume1/web/test2.php on line 17
Als iemand een alternatief script heeft voor de oplossing die ik zoek: een boodschappenlijst in de vorm van een soort bestellijst, dan houd ik me aanbevolen. Ik acht me zelf niet in staat prepared statements te maken en de loop aan te passen.
De rest van de meldingen zijn daar weer een gevolg van.
NB: $link bestaat altijd en is nooit leeg/false. Het zal een resource bevatten die NIET een werkende verbinding bevat. Daarom kom je niet op regel 9 uit.
Toevoeging op 23/08/2017 17:13:33:
mysqli_close($link) mag ook,
Mariadb 10 luistert op port 3307.
Mariadb 5 op port 3306.
oke, check. Ik ga het script nu weer opbouwen.
Code (php)
1
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
Dit gaat altijd in beeld komen, simpelweg om het feit dat er geen voorwaarde aan gesteld is.
Kijk eens naar je instellingen op de NAS, op welk poort nr staat je mysql ingesteld?
Zet deze op 3306, restart de mysql server en volg dan dit voorbeeld:
https://www.w3schools.com/php/func_mysqli_query.asp
Dit gebruik je voor Mariadb 5
Dit gebruik je voor Mariadb 10
OP EEN SYNOLOGY NAS WAAR BEIDE VERSIES TEGELIJKERTIJD KUNNEN DRAAIEN.
Als het niet duidelijk is, wil ik best harder knuppelen.
Keep calm... ;-)
Notice: Undefined variable: sql in test.php on line 42 Warning: mysqli_query() expects at least 2 parameters, 1 given in test.php on line 42 Warning: mysqli_error() expects exactly 1 parameter, 0 given in test.php on line 42
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
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
77
78
79
80
81
82
83
84
85
86
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
77
78
79
80
81
82
83
84
85
86
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$tbl_name = 'list';
$conn = new mysqli('127.0.0.1','root','','app', 3307);
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysqli_real_escape_string($_POST["item"][$id]);
$class = mysqli_real_escape_string($_POST["class"][$id]);
$unity = mysqli_real_escape_string($_POST["unity"][$id]);
$qty = mysqli_real_escape_string($_POST["qty"][$id]);
$memo = mysqli_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($update) or die(mysqli_error());
}
}
mysqli_query($conn,"SELECT id, item, class, unity, qty, memo FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id");
$conn->close();
$res = mysqli_query($sql) or die(mysqli_error());
if ( mysqli_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysqli_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
error_reporting(E_ALL);
ini_set('display_errors', true);
$tbl_name = 'list';
$conn = new mysqli('127.0.0.1','root','','app', 3307);
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysqli_real_escape_string($_POST["item"][$id]);
$class = mysqli_real_escape_string($_POST["class"][$id]);
$unity = mysqli_real_escape_string($_POST["unity"][$id]);
$qty = mysqli_real_escape_string($_POST["qty"][$id]);
$memo = mysqli_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($update) or die(mysqli_error());
}
}
mysqli_query($conn,"SELECT id, item, class, unity, qty, memo FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id");
$conn->close();
$res = mysqli_query($sql) or die(mysqli_error());
if ( mysqli_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysqli_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
Quote:
mysqli_query() expects at least 2 parameters, 1 given in test.php on line 42
Ik mis nog steeds een connectie-identifier.
idem dito voor mysqli_error()
Gewijzigd op 23/08/2017 21:53:36 door - Ariën -
Als iemand van jullie nog verbeteringen ziet, dan hoor ik het graag.
In ieder geval bedankt iedereen!
Hieronder mijn 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$username = "root";
$password = "";
$db = "app";
$tbl_name = "list";
$host = "127.0.0.1"; #ip-adres, "localhost" werkt niet
$port = "3307"; #poort wanneer MariaDB10 draait. MariaDB5 draait op 3306
$conn = new mysqli("$host", "$username", "$password", "$db", "$port");
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD'])
{
foreach( $_POST["id"] AS $id )
{
$item = mysqli_real_escape_string($conn,$_POST["item"][$id]);
$class = mysqli_real_escape_string($conn,$_POST["class"][$id]);
$unity = mysqli_real_escape_string($conn,$_POST["unity"][$id]);
$qty = mysqli_real_escape_string($conn,$_POST["qty"][$id]);
$memo = mysqli_real_escape_string($conn,$_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($conn,$update) or die( mysqli_error());
}
}
$query = "SELECT id, item, class, unity, qty, memo FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
when class = 'Kant-en-klaar maaltijden' then 31
when class = 'Vlees(vervangers)' then 40
when class = 'Vis' then 50
when class = 'Kruiden' then 60
when class = 'Gerechten' then 70
when class = 'Pasta(sauzen)' then 80
when class = 'Kruidenmixen' then 85
when class = 'Oosters' then 87
when class = 'Rijst en mie' then 90
when class = 'Vis- en vleesconserven' then 95
when class = 'Zuivel' then 100
when class = 'Soepen' then 110
when class = 'Groente- en fruitconserven' then 120
when class = 'Olieen en azijn' then 130
when class = 'Tapas' then 133
when class = 'Sauzen' then 135
when class = 'Snoep' then 140
when class = 'Sappen en frisdrank' then 150
when class = 'Chips en zoutjes' then 160
when class = 'Bier en wijn' then 170
when class = 'Boter' then 180
when class = 'Wasmiddel en reinigers' then 190
when class = 'Huishoudelijke artikelen' then 195
when class = 'Dierenvoeding' then 200
when class = 'Persoonlijke verzorging' then 210
when class = 'Koek' then 220
when class = 'Papierwaren en lectuur' then 230
when class = 'Koffie en thee' then 240
when class = 'Babyvoeding en luiers' then 250
when class = 'Voorverpakte vleeswaren' then 255
when class = 'Tussendoortjes' then 260
when class = 'Ontbijtgranen' then 270
when class = 'Broodbeleg' then 280
when class = 'Bakmiddel / suiker' then 290
when class = 'Eieren' then 300
when class = 'Broodsalades' then 305
when class = 'Kaas' then 310
when class = 'Houdbare zuivel' then 320
when class = 'Diepvries' then 330
when class = 'Vleeswaren' then 340
when class = 'Brood' then 350
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id";
$result = mysqli_query($conn,$query) or die( mysqli_error() );
if (mysqli_num_rows($result) > 0)
{
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ($row = mysqli_fetch_assoc($result)) {
if ( $row["qty"] == '0' )
{
$class = 'form-control-inactief';
}
else
{
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' <option value="Kant-en-klaar maaltijden"'. ($row['class'] == 'Kant-en-klaar maaltijden' ? ' selected="selected"' : '') .'>Kant-en-klaar maaltijden</option>'."\n";
echo ' <option value="Vlees(vervangers)"'. ($row['class'] == 'Vlees(vervangers)' ? ' selected="selected"' : '') .'>Vlees(vervangers)</option>'."\n";
echo ' <option value="Vis"'. ($row['class'] == 'Vis' ? ' selected="selected"' : '') .'>Vis</option>'."\n";
echo ' <option value="Kruiden"'. ($row['class'] == 'Kruiden' ? ' selected="selected"' : '') .'>Kruiden</option>'."\n";
echo ' <option value="Gerechten"'. ($row['class'] == 'Gerechten' ? ' selected="selected"' : '') .'>Gerechten</option>'."\n";
echo ' <option value="Pasta(sauzen)"'. ($row['class'] == 'Pasta(sauzen)' ? ' selected="selected"' : '') .'>Pasta(sauzen)</option>'."\n";
echo ' <option value="Kruidenmixen"'. ($row['class'] == 'Kruidenmixen' ? ' selected="selected"' : '') .'>Kruidenmixen</option>'."\n";
echo ' <option value="Oosters"'. ($row['class'] == 'Oosters' ? ' selected="selected"' : '') .'>Oosters</option>'."\n";
echo ' <option value="Vis- en vleesconserven"'. ($row['class'] == 'Vis- en vleesconserven' ? ' selected="selected"' : '') .'>Vis- en vleesconserven</option>'."\n";
echo ' <option value="Rijst en mie"'. ($row['class'] == 'Rijst en mie' ? ' selected="selected"' : '') .'>Rijst en mie</option>'."\n";
echo ' <option value="Zuivel"'. ($row['class'] == 'Zuivel' ? ' selected="selected"' : '') .'>Zuivel</option>'."\n";
echo ' <option value="Soepen"'. ($row['class'] == 'Soepen' ? ' selected="selected"' : '') .'>Soepen</option>'."\n";
echo ' <option value="Groente- en fruitconserven"'. ($row['class'] == 'Groente- en fruitconserven' ? ' selected="selected"' : '') .'>Groente- en fruitconserven</option>'."\n";
echo ' <option value="Olieen en azijn"'. ($row['class'] == 'Olieen en azijn' ? ' selected="selected"' : '') .'>Olieen en azijn</option>'."\n";
echo ' <option value="Tapas"'. ($row['class'] == 'Tapas' ? ' selected="selected"' : '') .'>Tapas</option>'."\n";
echo ' <option value="Sauzen"'. ($row['class'] == 'Sauzen' ? ' selected="selected"' : '') .'>Sauzen</option>'."\n";
echo ' <option value="Snoep"'. ($row['class'] == 'Snoep' ? ' selected="selected"' : '') .'>Snoep</option>'."\n";
echo ' <option value="Sappen en frisdrank"'. ($row['class'] == 'Sappen en frisdrank' ? ' selected="selected"' : '') .'>Sappen en frisdrank</option>'."\n";
echo ' <option value="Chips en zoutjes"'. ($row['class'] == 'Chips en zoutjes' ? ' selected="selected"' : '') .'>Chips en zoutjes</option>'."\n";
echo ' <option value="Bier en wijn"'. ($row['class'] == 'Bier en wijn' ? ' selected="selected"' : '') .'>Bier en wijn</option>'."\n";
echo ' <option value="Boter"'. ($row['class'] == 'Boter' ? ' selected="selected"' : '') .'>Boter</option>'."\n";
echo ' <option value="Wasmiddel en reinigers"'. ($row['class'] == 'Wasmiddel en reinigers' ? ' selected="selected"' : '') .'>Wasmiddel en reinigers</option>'."\n";
echo ' <option value="Huishoudelijke artikelen"'. ($row['class'] == 'Huishoudelijke artikelen' ? ' selected="selected"' : '') .'>Huishoudelijke artikelen</option>'."\n";
echo ' <option value="Dierenvoeding"'. ($row['class'] == 'Dierenvoeding' ? ' selected="selected"' : '') .'>Dierenvoeding</option>'."\n";
echo ' <option value="Persoonlijke verzorging"'. ($row['class'] == 'Persoonlijke verzorging' ? ' selected="selected"' : '') .'>Persoonlijke verzorging</option>'."\n";
echo ' <option value="Koek"'. ($row['class'] == 'Koek' ? ' selected="selected"' : '') .'>Koek</option>'."\n";
echo ' <option value="Papierwaren en lectuur"'. ($row['class'] == 'Papierwaren en lectuur' ? ' selected="selected"' : '') .'>Papierwaren en lectuur</option>'."\n";
echo ' <option value="Koffie en thee"'. ($row['class'] == 'Koffie en thee' ? ' selected="selected"' : '') .'>Koffie en thee</option>'."\n";
echo ' <option value="Babyvoeding en luiers"'. ($row['class'] == 'Babyvoeding en luiers' ? ' selected="selected"' : '') .'>Babyvoeding en luiers</option>'."\n";
echo ' <option value="Voorverpakte vleeswaren"'. ($row['class'] == 'Voorverpakte vleeswaren' ? ' selected="selected"' : '') .'>Voorverpakte vleeswaren</option>'."\n";
echo ' <option value="Tussendoortjes"'. ($row['class'] == 'Tussendoortjes' ? ' selected="selected"' : '') .'>Tussendoortjes</option>'."\n";
echo ' <option value="Ontbijtgranen"'. ($row['class'] == 'Ontbijtgranen' ? ' selected="selected"' : '') .'>Ontbijtgranen</option>'."\n";
echo ' <option value="Broodbeleg"'. ($row['class'] == 'Broodbeleg' ? ' selected="selected"' : '') .'>Broodbeleg</option>'."\n";
echo ' <option value="Bakmiddel / suiker"'. ($row['class'] == 'Bakmiddel / suiker' ? ' selected="selected"' : '') .'>Bakmiddel / suiker</option>'."\n";
echo ' <option value="Eieren"'. ($row['class'] == 'Eieren' ? ' selected="selected"' : '') .'>Eieren</option>'."\n";
echo ' <option value="Broodsalades"'. ($row['class'] == 'Broodsalades' ? ' selected="selected"' : '') .'>Broodsalades</option>'."\n";
echo ' <option value="Kaas"'. ($row['class'] == 'Kaas' ? ' selected="selected"' : '') .'>Kaas</option>'."\n";
echo ' <option value="Houdbare zuivel"'. ($row['class'] == 'Houdbare zuivel' ? ' selected="selected"' : '') .'>Houdbare zuivel</option>'."\n";
echo ' <option value="Diepvries"'. ($row['class'] == 'Diepvries' ? ' selected="selected"' : '') .'>Diepvries</option>'."\n";
echo ' <option value="Vleeswaren"'. ($row['class'] == 'Vleeswaren' ? ' selected="selected"' : '') .'>Vleeswaren</option>'."\n";
echo ' <option value="Brood"'. ($row['class'] == 'Brood' ? ' selected="selected"' : '') .'>Brood</option>'."\n";
echo ' </select>'."\n";
//echo '<input type="submit" name="submit" value="..">' . "\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
mysqli_free_result($result);
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
$conn->close();
?>
error_reporting(E_ALL);
ini_set('display_errors', true);
$username = "root";
$password = "";
$db = "app";
$tbl_name = "list";
$host = "127.0.0.1"; #ip-adres, "localhost" werkt niet
$port = "3307"; #poort wanneer MariaDB10 draait. MariaDB5 draait op 3306
$conn = new mysqli("$host", "$username", "$password", "$db", "$port");
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD'])
{
foreach( $_POST["id"] AS $id )
{
$item = mysqli_real_escape_string($conn,$_POST["item"][$id]);
$class = mysqli_real_escape_string($conn,$_POST["class"][$id]);
$unity = mysqli_real_escape_string($conn,$_POST["unity"][$id]);
$qty = mysqli_real_escape_string($conn,$_POST["qty"][$id]);
$memo = mysqli_real_escape_string($conn,$_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($conn,$update) or die( mysqli_error());
}
}
$query = "SELECT id, item, class, unity, qty, memo FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
when class = 'Kant-en-klaar maaltijden' then 31
when class = 'Vlees(vervangers)' then 40
when class = 'Vis' then 50
when class = 'Kruiden' then 60
when class = 'Gerechten' then 70
when class = 'Pasta(sauzen)' then 80
when class = 'Kruidenmixen' then 85
when class = 'Oosters' then 87
when class = 'Rijst en mie' then 90
when class = 'Vis- en vleesconserven' then 95
when class = 'Zuivel' then 100
when class = 'Soepen' then 110
when class = 'Groente- en fruitconserven' then 120
when class = 'Olieen en azijn' then 130
when class = 'Tapas' then 133
when class = 'Sauzen' then 135
when class = 'Snoep' then 140
when class = 'Sappen en frisdrank' then 150
when class = 'Chips en zoutjes' then 160
when class = 'Bier en wijn' then 170
when class = 'Boter' then 180
when class = 'Wasmiddel en reinigers' then 190
when class = 'Huishoudelijke artikelen' then 195
when class = 'Dierenvoeding' then 200
when class = 'Persoonlijke verzorging' then 210
when class = 'Koek' then 220
when class = 'Papierwaren en lectuur' then 230
when class = 'Koffie en thee' then 240
when class = 'Babyvoeding en luiers' then 250
when class = 'Voorverpakte vleeswaren' then 255
when class = 'Tussendoortjes' then 260
when class = 'Ontbijtgranen' then 270
when class = 'Broodbeleg' then 280
when class = 'Bakmiddel / suiker' then 290
when class = 'Eieren' then 300
when class = 'Broodsalades' then 305
when class = 'Kaas' then 310
when class = 'Houdbare zuivel' then 320
when class = 'Diepvries' then 330
when class = 'Vleeswaren' then 340
when class = 'Brood' then 350
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id";
$result = mysqli_query($conn,$query) or die( mysqli_error() );
if (mysqli_num_rows($result) > 0)
{
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ($row = mysqli_fetch_assoc($result)) {
if ( $row["qty"] == '0' )
{
$class = 'form-control-inactief';
}
else
{
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' <option value="Kant-en-klaar maaltijden"'. ($row['class'] == 'Kant-en-klaar maaltijden' ? ' selected="selected"' : '') .'>Kant-en-klaar maaltijden</option>'."\n";
echo ' <option value="Vlees(vervangers)"'. ($row['class'] == 'Vlees(vervangers)' ? ' selected="selected"' : '') .'>Vlees(vervangers)</option>'."\n";
echo ' <option value="Vis"'. ($row['class'] == 'Vis' ? ' selected="selected"' : '') .'>Vis</option>'."\n";
echo ' <option value="Kruiden"'. ($row['class'] == 'Kruiden' ? ' selected="selected"' : '') .'>Kruiden</option>'."\n";
echo ' <option value="Gerechten"'. ($row['class'] == 'Gerechten' ? ' selected="selected"' : '') .'>Gerechten</option>'."\n";
echo ' <option value="Pasta(sauzen)"'. ($row['class'] == 'Pasta(sauzen)' ? ' selected="selected"' : '') .'>Pasta(sauzen)</option>'."\n";
echo ' <option value="Kruidenmixen"'. ($row['class'] == 'Kruidenmixen' ? ' selected="selected"' : '') .'>Kruidenmixen</option>'."\n";
echo ' <option value="Oosters"'. ($row['class'] == 'Oosters' ? ' selected="selected"' : '') .'>Oosters</option>'."\n";
echo ' <option value="Vis- en vleesconserven"'. ($row['class'] == 'Vis- en vleesconserven' ? ' selected="selected"' : '') .'>Vis- en vleesconserven</option>'."\n";
echo ' <option value="Rijst en mie"'. ($row['class'] == 'Rijst en mie' ? ' selected="selected"' : '') .'>Rijst en mie</option>'."\n";
echo ' <option value="Zuivel"'. ($row['class'] == 'Zuivel' ? ' selected="selected"' : '') .'>Zuivel</option>'."\n";
echo ' <option value="Soepen"'. ($row['class'] == 'Soepen' ? ' selected="selected"' : '') .'>Soepen</option>'."\n";
echo ' <option value="Groente- en fruitconserven"'. ($row['class'] == 'Groente- en fruitconserven' ? ' selected="selected"' : '') .'>Groente- en fruitconserven</option>'."\n";
echo ' <option value="Olieen en azijn"'. ($row['class'] == 'Olieen en azijn' ? ' selected="selected"' : '') .'>Olieen en azijn</option>'."\n";
echo ' <option value="Tapas"'. ($row['class'] == 'Tapas' ? ' selected="selected"' : '') .'>Tapas</option>'."\n";
echo ' <option value="Sauzen"'. ($row['class'] == 'Sauzen' ? ' selected="selected"' : '') .'>Sauzen</option>'."\n";
echo ' <option value="Snoep"'. ($row['class'] == 'Snoep' ? ' selected="selected"' : '') .'>Snoep</option>'."\n";
echo ' <option value="Sappen en frisdrank"'. ($row['class'] == 'Sappen en frisdrank' ? ' selected="selected"' : '') .'>Sappen en frisdrank</option>'."\n";
echo ' <option value="Chips en zoutjes"'. ($row['class'] == 'Chips en zoutjes' ? ' selected="selected"' : '') .'>Chips en zoutjes</option>'."\n";
echo ' <option value="Bier en wijn"'. ($row['class'] == 'Bier en wijn' ? ' selected="selected"' : '') .'>Bier en wijn</option>'."\n";
echo ' <option value="Boter"'. ($row['class'] == 'Boter' ? ' selected="selected"' : '') .'>Boter</option>'."\n";
echo ' <option value="Wasmiddel en reinigers"'. ($row['class'] == 'Wasmiddel en reinigers' ? ' selected="selected"' : '') .'>Wasmiddel en reinigers</option>'."\n";
echo ' <option value="Huishoudelijke artikelen"'. ($row['class'] == 'Huishoudelijke artikelen' ? ' selected="selected"' : '') .'>Huishoudelijke artikelen</option>'."\n";
echo ' <option value="Dierenvoeding"'. ($row['class'] == 'Dierenvoeding' ? ' selected="selected"' : '') .'>Dierenvoeding</option>'."\n";
echo ' <option value="Persoonlijke verzorging"'. ($row['class'] == 'Persoonlijke verzorging' ? ' selected="selected"' : '') .'>Persoonlijke verzorging</option>'."\n";
echo ' <option value="Koek"'. ($row['class'] == 'Koek' ? ' selected="selected"' : '') .'>Koek</option>'."\n";
echo ' <option value="Papierwaren en lectuur"'. ($row['class'] == 'Papierwaren en lectuur' ? ' selected="selected"' : '') .'>Papierwaren en lectuur</option>'."\n";
echo ' <option value="Koffie en thee"'. ($row['class'] == 'Koffie en thee' ? ' selected="selected"' : '') .'>Koffie en thee</option>'."\n";
echo ' <option value="Babyvoeding en luiers"'. ($row['class'] == 'Babyvoeding en luiers' ? ' selected="selected"' : '') .'>Babyvoeding en luiers</option>'."\n";
echo ' <option value="Voorverpakte vleeswaren"'. ($row['class'] == 'Voorverpakte vleeswaren' ? ' selected="selected"' : '') .'>Voorverpakte vleeswaren</option>'."\n";
echo ' <option value="Tussendoortjes"'. ($row['class'] == 'Tussendoortjes' ? ' selected="selected"' : '') .'>Tussendoortjes</option>'."\n";
echo ' <option value="Ontbijtgranen"'. ($row['class'] == 'Ontbijtgranen' ? ' selected="selected"' : '') .'>Ontbijtgranen</option>'."\n";
echo ' <option value="Broodbeleg"'. ($row['class'] == 'Broodbeleg' ? ' selected="selected"' : '') .'>Broodbeleg</option>'."\n";
echo ' <option value="Bakmiddel / suiker"'. ($row['class'] == 'Bakmiddel / suiker' ? ' selected="selected"' : '') .'>Bakmiddel / suiker</option>'."\n";
echo ' <option value="Eieren"'. ($row['class'] == 'Eieren' ? ' selected="selected"' : '') .'>Eieren</option>'."\n";
echo ' <option value="Broodsalades"'. ($row['class'] == 'Broodsalades' ? ' selected="selected"' : '') .'>Broodsalades</option>'."\n";
echo ' <option value="Kaas"'. ($row['class'] == 'Kaas' ? ' selected="selected"' : '') .'>Kaas</option>'."\n";
echo ' <option value="Houdbare zuivel"'. ($row['class'] == 'Houdbare zuivel' ? ' selected="selected"' : '') .'>Houdbare zuivel</option>'."\n";
echo ' <option value="Diepvries"'. ($row['class'] == 'Diepvries' ? ' selected="selected"' : '') .'>Diepvries</option>'."\n";
echo ' <option value="Vleeswaren"'. ($row['class'] == 'Vleeswaren' ? ' selected="selected"' : '') .'>Vleeswaren</option>'."\n";
echo ' <option value="Brood"'. ($row['class'] == 'Brood' ? ' selected="selected"' : '') .'>Brood</option>'."\n";
echo ' </select>'."\n";
//echo '<input type="submit" name="submit" value="..">' . "\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
mysqli_free_result($result);
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
$conn->close();
?>
Dat kan wel, maar ikzelf raad het niet aan als je later extra functies bijvoorbeeld wilt toevoegen, en bovendien schept hij bij sommige functies ook verwarring.
Ik raad aan om die Object-Georienteerde versie te gebruiken en dus: $conn->query($sql); etc...
Dit is een stuk schaalbaarder.
Tevens is een heel blok met op elke regel een echo niet echt nodig. Je kan dit prima buiten PHP-tags houden, en op plekken waar je PHP nodig hebt, deze apart te openen en af te sluiten.
De beide mysqli_error() missen nog steeds een argument.