Dropdown lijst reset naar eerste optie in lijst bij editen
Ik ben met een project bezig, de bedoeling is dat ik een configuratiemanagement applicatie maak.
Alles werkt prima, het enigste waar ik nog problemen mee heb is dat ik verschillende dropdown lijstjes heb bij het aanmaken van een nieuwe configuratie waar ik bijvoorbeeld de keuze Ja of Nee heb en/of een lijst met IP adressen die opgehaald worden uit een andere tabel.
Als ik die keuzes heb gemaakt en de configuratie opsla en daarna wil wijzigen worden de keuzes die ik heb gemaakt gereset naar het bovenste/eerste item in die dropdown lijst.
Hij onthoud de keuze die ik heb gemaakt als ik een bestaande configuratie wil wijzigen, maar als ik een nieuwe configuratie wil toevoegen geeft hij een foutmelding: Notice: Undefined variable: gresult in C:xampp\htdocs\cmdb2\config2.php on line 130 >JA
Ik denk dat dit komt omdat de applicatie een keuze uit de database probeert op te halen die nog niet bestaat?
Ik denk zelf dat het te iets te maken heeft met een if else.., hoe kan ik dit oplossen?
Nu heb ik al het een en andere zitten proberen en dat is redelijk succesvol:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Gewijzigd op 19/06/2015 10:31:04 door Niels Hurkmans
Of misschien wel specifieker.
met $gresult["dhcp"] ipv de gehele variabele $gresult.
Maar misschien krijg je dan weer errors op $gresult["dhcp"].
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php
if(isset($gresult["dhcp"])):?>
<select name="dhcp" >
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '')>JA</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '')>NEE</option>
</select>
<?php endif; ?>
</td>
</tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php
if(isset($gresult["dhcp"])):?>
<select name="dhcp" >
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '')>JA</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '')>NEE</option>
</select>
<?php endif; ?>
</td>
</tr>
Er zal iets niet goed worden afgesloten ofzo
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html>
<head>
<title>update.php - .</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<script>
$(document).ready(function() {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("Vul dit veld in aub");
}
};
elements[i].oninput = function(e) {
e.target.setCustomValidity("");
};
}
})
</script>
<body>
<?php
$mysqli = new mysqli('localhost','root','');
$mysqli->select_db('cmdb');
$dhcp_select = $gresult["dhcp"] ;
?>
<div class="wrapper">
<div class="content" style="width: 500px !important;">
<?php include 'header.php'; ?><br/>
<div>
<form id="frmContact" method="POST" action="config1.php"
onSubmit="return Validate();">
<input type="hidden" name="id"
value="<?php echo (isset($gresult) ? $gresult["id"] : ''); ?>" />
<table>
<tr>
<td>
<label for="fname">PC Naam: </label>
</td>
<td>
<input type="text" name="pc_naam"
value="<?php echo (isset($gresult) ? $gresult["pc_naam"] : ''); ?>"
id="pc_naam" class="txt-fld" required />
</td>
</tr>
<tr>
<td>
<label for="fname">Merk: </label>
</td>
<td>
<input type="text" name="merk"
value="<?php echo (isset($gresult) ? $gresult["merk"] : ''); ?>"
id="merk" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Type: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `hardware` ORDER BY `hardware`");
echo '<select name=type>';
while($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['hardware'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serienummer: </label>
</td>
<td>
<input type="text" name="serienummer" maxlength="30"
value="<?php echo (isset($gresult) ? $gresult["serienummer"] : ''); ?>"
class="txt-fld" />
</td>
</tr>
<tr>
<td>
<label for="fname">OS: </label>
</td>
<td>
<select name="os" required></br>
<option>Windows XP</option>
<option>Windows Vista 32 Bits</option>
<option>Windows Vista 64 Bits</option>
<option>Windows 7 32 Bits</option>
<option>Windows 7 64 Bits</option>
<option>Windows Server</option>
<option>Niet van toepassing</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="fname">IP Adres: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `ip_adressen` ORDER BY `ip_adres`");
echo '<select name=ip_adres>';
while($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['ip_adres'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php
if(isset($gresult["dhcp"])):?>
<select name="dhcp" >
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '')>JA</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '')>NEE</option>
</select>
<?php endif; ?>
</td>
</tr>
<tr>
<td>
<label for="fname">Patchpunt: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `patch` ORDER BY `patchpunt`");
echo '<select name=patchpunt>';
while($rows = $result->fetch_assoc()) {
?> <option <?php if($gresult["patchpunt"] == $rows["patchpunt"]) echo 'selected="selected"'; echo '>' . $rows['patchpunt'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serial Key: </label>
</td>
<td>
<input type="text" name="serial_key" maxlength="30"
value="<?php echo (isset($gresult) ? $gresult["serial_key"] : ''); ?>"
id="serial_key" class="txt-fld" />
</td>
</tr>
<tr>
<td>
<label for="fname">Gebruiker: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `gebruikers` ORDER BY `gebruikersnaam`");
echo '<select name=gebruikersnaam>';
while($rows = $result->fetch_assoc()) {
?> <option <?php if($gresult["gebruiker"] == $rows["gebruikersnaam"]) echo 'selected="selected"'; echo '>' . $rows['gebruiker'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Locatie: </label>
</td>
<td>
<input type="text" name="locatie"
value="<?php echo (isset($gresult) ? $gresult["locatie"] : ''); ?>"
id="locatie" class="txt-fld" required/>
</td>
</tr>
</table>
<script>
function goBack() {
window.history.back();
}
</script>
<input type="hidden" name="action_type" value="<?php echo (isset($gresult) ? 'edit' : 'add');?>"/>
<div style="text-align: center; padding-top: 30px;">
<input class="btn" type="submit" name="save" id="save" value="Opslaan" />
<input class="btn" type="submit" name="save" id="cancel" value="Cancel" onclick=" return goBack();"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<html>
<head>
<title>update.php - .</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<script>
$(document).ready(function() {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("Vul dit veld in aub");
}
};
elements[i].oninput = function(e) {
e.target.setCustomValidity("");
};
}
})
</script>
<body>
<?php
$mysqli = new mysqli('localhost','root','');
$mysqli->select_db('cmdb');
$dhcp_select = $gresult["dhcp"] ;
?>
<div class="wrapper">
<div class="content" style="width: 500px !important;">
<?php include 'header.php'; ?><br/>
<div>
<form id="frmContact" method="POST" action="config1.php"
onSubmit="return Validate();">
<input type="hidden" name="id"
value="<?php echo (isset($gresult) ? $gresult["id"] : ''); ?>" />
<table>
<tr>
<td>
<label for="fname">PC Naam: </label>
</td>
<td>
<input type="text" name="pc_naam"
value="<?php echo (isset($gresult) ? $gresult["pc_naam"] : ''); ?>"
id="pc_naam" class="txt-fld" required />
</td>
</tr>
<tr>
<td>
<label for="fname">Merk: </label>
</td>
<td>
<input type="text" name="merk"
value="<?php echo (isset($gresult) ? $gresult["merk"] : ''); ?>"
id="merk" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Type: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `hardware` ORDER BY `hardware`");
echo '<select name=type>';
while($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['hardware'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serienummer: </label>
</td>
<td>
<input type="text" name="serienummer" maxlength="30"
value="<?php echo (isset($gresult) ? $gresult["serienummer"] : ''); ?>"
class="txt-fld" />
</td>
</tr>
<tr>
<td>
<label for="fname">OS: </label>
</td>
<td>
<select name="os" required></br>
<option>Windows XP</option>
<option>Windows Vista 32 Bits</option>
<option>Windows Vista 64 Bits</option>
<option>Windows 7 32 Bits</option>
<option>Windows 7 64 Bits</option>
<option>Windows Server</option>
<option>Niet van toepassing</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="fname">IP Adres: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `ip_adressen` ORDER BY `ip_adres`");
echo '<select name=ip_adres>';
while($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['ip_adres'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php
if(isset($gresult["dhcp"])):?>
<select name="dhcp" >
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '')>JA</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '')>NEE</option>
</select>
<?php endif; ?>
</td>
</tr>
<tr>
<td>
<label for="fname">Patchpunt: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `patch` ORDER BY `patchpunt`");
echo '<select name=patchpunt>';
while($rows = $result->fetch_assoc()) {
?> <option <?php if($gresult["patchpunt"] == $rows["patchpunt"]) echo 'selected="selected"'; echo '>' . $rows['patchpunt'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serial Key: </label>
</td>
<td>
<input type="text" name="serial_key" maxlength="30"
value="<?php echo (isset($gresult) ? $gresult["serial_key"] : ''); ?>"
id="serial_key" class="txt-fld" />
</td>
</tr>
<tr>
<td>
<label for="fname">Gebruiker: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `gebruikers` ORDER BY `gebruikersnaam`");
echo '<select name=gebruikersnaam>';
while($rows = $result->fetch_assoc()) {
?> <option <?php if($gresult["gebruiker"] == $rows["gebruikersnaam"]) echo 'selected="selected"'; echo '>' . $rows['gebruiker'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Locatie: </label>
</td>
<td>
<input type="text" name="locatie"
value="<?php echo (isset($gresult) ? $gresult["locatie"] : ''); ?>"
id="locatie" class="txt-fld" required/>
</td>
</tr>
</table>
<script>
function goBack() {
window.history.back();
}
</script>
<input type="hidden" name="action_type" value="<?php echo (isset($gresult) ? 'edit' : 'add');?>"/>
<div style="text-align: center; padding-top: 30px;">
<input class="btn" type="submit" name="save" id="save" value="Opslaan" />
<input class="btn" type="submit" name="save" id="cancel" value="Cancel" onclick=" return goBack();"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html>
<head>
<title>update.php - .</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<script>
$(document).ready(function () {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function (e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("Vul dit veld in aub");
}
};
elements[i].oninput = function (e) {
e.target.setCustomValidity("");
};
}
})
</script>
<body>
<?php
$mysqli = new mysqli('localhost', 'root', '');
$mysqli->select_db('cmdb');
$dhcp_select = $gresult["dhcp"];
?>
<div class="wrapper">
<div class="content" style="width: 500px !important;">
<?php include 'header.php'; ?><br/>
<div>
<form id="frmContact" method="POST" action="config1.php"
onSubmit="return Validate();">
<input type="hidden" name="id"
value="<?php echo(isset($gresult) ? $gresult["id"] : ''); ?>"/>
<table>
<tr>
<td>
<label for="fname">PC Naam: </label>
</td>
<td>
<input type="text" name="pc_naam"
value="<?php echo(isset($gresult) ? $gresult["pc_naam"] : ''); ?>"
id="pc_naam" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Merk: </label>
</td>
<td>
<input type="text" name="merk"
value="<?php echo(isset($gresult) ? $gresult["merk"] : ''); ?>"
id="merk" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Type: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `hardware` ORDER BY `hardware`");
echo '<select name=type>';
while ($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['hardware'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serienummer: </label>
</td>
<td>
<input type="text" name="serienummer" maxlength="30"
value="<?= ($gresult != '' ? $gresult["serienummer"] : '') ?>"
class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="fname">OS: </label>
</td>
<td>
<select name="os" required></br>
<option>Windows XP</option>
<option>Windows Vista 32 Bits</option>
<option>Windows Vista 64 Bits</option>
<option>Windows 7 32 Bits</option>
<option>Windows 7 64 Bits</option>
<option>Windows Server</option>
<option>Niet van toepassing</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="fname">IP Adres: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `ip_adressen` ORDER BY `ip_adres`");
echo '<select name=ip_adres>';
while ($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['ip_adres'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php if (isset($gresult["dhcp"])): ?>
<select name="dhcp">
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '') ?>JA
</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '') ?>NEE
</option>
</select>
<?php endif; ?>
</td>
</tr>
<tr>
<td>
<label for="fname">Patchpunt: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `patch` ORDER BY `patchpunt`");
echo '<select name=patchpunt>';
while ($rows = $result->fetch_assoc()) {
?>
<option <?php if ($gresult["patchpunt"] == $rows["patchpunt"]) {
echo 'selected="selected"';
} echo '>' . $rows['patchpunt'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serial Key: </label>
</td>
<td>
<input type="text" name="serial_key" maxlength="30"
value="<?php echo(isset($gresult) ? $gresult["serial_key"] : ''); ?>"
id="serial_key" class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="fname">Gebruiker: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `gebruikers` ORDER BY `gebruikersnaam`");
echo '<select name=gebruikersnaam>';
while ($rows = $result->fetch_assoc()) {
?>
<option <?php if ($gresult["gebruiker"] == $rows["gebruikersnaam"]) {
echo 'selected="selected"';
} echo '>' . $rows['gebruiker'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Locatie: </label>
</td>
<td>
<input type="text" name="locatie"
value="<?php echo(isset($gresult) ? $gresult["locatie"] : ''); ?>"
id="locatie" class="txt-fld" required/>
</td>
</tr>
</table>
<script>
function goBack() {
window.history.back();
}
</script>
<input type="hidden" name="action_type" value="<?php echo(isset($gresult) ? 'edit' : 'add'); ?>"/>
<div style="text-align: center; padding-top: 30px;">
<input class="btn" type="submit" name="save" id="save" value="Opslaan"/>
<input class="btn" type="submit" name="save" id="cancel" value="Cancel"
onclick=" return goBack();"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<html>
<head>
<title>update.php - .</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<script>
$(document).ready(function () {
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function (e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("Vul dit veld in aub");
}
};
elements[i].oninput = function (e) {
e.target.setCustomValidity("");
};
}
})
</script>
<body>
<?php
$mysqli = new mysqli('localhost', 'root', '');
$mysqli->select_db('cmdb');
$dhcp_select = $gresult["dhcp"];
?>
<div class="wrapper">
<div class="content" style="width: 500px !important;">
<?php include 'header.php'; ?><br/>
<div>
<form id="frmContact" method="POST" action="config1.php"
onSubmit="return Validate();">
<input type="hidden" name="id"
value="<?php echo(isset($gresult) ? $gresult["id"] : ''); ?>"/>
<table>
<tr>
<td>
<label for="fname">PC Naam: </label>
</td>
<td>
<input type="text" name="pc_naam"
value="<?php echo(isset($gresult) ? $gresult["pc_naam"] : ''); ?>"
id="pc_naam" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Merk: </label>
</td>
<td>
<input type="text" name="merk"
value="<?php echo(isset($gresult) ? $gresult["merk"] : ''); ?>"
id="merk" class="txt-fld" required/>
</td>
</tr>
<tr>
<td>
<label for="fname">Type: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `hardware` ORDER BY `hardware`");
echo '<select name=type>';
while ($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['hardware'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serienummer: </label>
</td>
<td>
<input type="text" name="serienummer" maxlength="30"
value="<?= ($gresult != '' ? $gresult["serienummer"] : '') ?>"
class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="fname">OS: </label>
</td>
<td>
<select name="os" required></br>
<option>Windows XP</option>
<option>Windows Vista 32 Bits</option>
<option>Windows Vista 64 Bits</option>
<option>Windows 7 32 Bits</option>
<option>Windows 7 64 Bits</option>
<option>Windows Server</option>
<option>Niet van toepassing</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="fname">IP Adres: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `ip_adressen` ORDER BY `ip_adres`");
echo '<select name=ip_adres>';
while ($rows = $result->fetch_assoc()) {
echo "<option>" . $rows['ip_adres'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">DHCP: </label>
</td>
<td>
<?php if (isset($gresult["dhcp"])): ?>
<select name="dhcp">
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '') ?>JA
</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '') ?>NEE
</option>
</select>
<?php endif; ?>
</td>
</tr>
<tr>
<td>
<label for="fname">Patchpunt: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `patch` ORDER BY `patchpunt`");
echo '<select name=patchpunt>';
while ($rows = $result->fetch_assoc()) {
?>
<option <?php if ($gresult["patchpunt"] == $rows["patchpunt"]) {
echo 'selected="selected"';
} echo '>' . $rows['patchpunt'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Serial Key: </label>
</td>
<td>
<input type="text" name="serial_key" maxlength="30"
value="<?php echo(isset($gresult) ? $gresult["serial_key"] : ''); ?>"
id="serial_key" class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="fname">Gebruiker: </label>
</td>
<td>
<?php
$result = $mysqli->query("SELECT * FROM `gebruikers` ORDER BY `gebruikersnaam`");
echo '<select name=gebruikersnaam>';
while ($rows = $result->fetch_assoc()) {
?>
<option <?php if ($gresult["gebruiker"] == $rows["gebruikersnaam"]) {
echo 'selected="selected"';
} echo '>' . $rows['gebruiker'] . "</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>
<label for="fname">Locatie: </label>
</td>
<td>
<input type="text" name="locatie"
value="<?php echo(isset($gresult) ? $gresult["locatie"] : ''); ?>"
id="locatie" class="txt-fld" required/>
</td>
</tr>
</table>
<script>
function goBack() {
window.history.back();
}
</script>
<input type="hidden" name="action_type" value="<?php echo(isset($gresult) ? 'edit' : 'add'); ?>"/>
<div style="text-align: center; padding-top: 30px;">
<input class="btn" type="submit" name="save" id="save" value="Opslaan"/>
<input class="btn" type="submit" name="save" id="cancel" value="Cancel"
onclick=" return goBack();"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Op een aantal plaatsen waar je dat niet doet (maar er vanuit gaat dat deze al bestaat) gaat het mis.
Conclusie: $gresult is niet gedefinieerd.
Trouwens, als je een YES/NO veld hebt, zou een checkbox (of zelfs een radiobutton) niet een geschikter formulierelementtype zijn?