?
Onbekende gebruiker
19-06-2015 10:49
Ik denk dat je moet gaan checken of je data hebt die je anders wilt wwegeven.
<?php
if(isset($variabele)) {
// hier dan de dropdown weergeven
}
?>
Link gekopieerd
Zo dan?
<?php
if(isset($gresult)) {
<select name="dhcp" required></br>
<option <?php if($gresult["dhcp"] == "JA") echo 'selected="selected"';?>>JA</option>
<option <?php if($gresult["dhcp"] == "NEE") echo 'selected="selected"';?>>NEE</option>
</select>
}
?>
Link gekopieerd
?
Onbekende gebruiker
19-06-2015 11:12
Ja dat kan inderdaad.
Of misschien wel specifieker.
met $gresult["dhcp"] ipv de gehele variabele $gresult.
Maar misschien krijg je dan weer errors op $gresult["dhcp"].
Link gekopieerd
Ik krijg nu een syntax error: unexpected '<' online 132 ?
<?php
if(isset($gresult["dhcp"])) {
<select name="dhcp" required></br>
<option [code]<?php if($gresult["dhcp"] == "JA") echo 'selected="selected"';?>>JA</option>
<option <?php if($gresult["dhcp"] == "NEE") echo 'selected="selected"';?>>NEE</option>
</select>
}
?>
Link gekopieerd
?
Onbekende gebruiker
19-06-2015 11:21
Probeer dit eens. Maakt je code ook wat leesbaarder
<?php
if(isset($gresult["dhcp"])):?>
<select name="dhcp" required>
<option <?= ($gresult["dhcp"] == "JA" ? 'selected="selected' : '')>JA</option>
<option <?= ($gresult["dhcp"] == "NEE" ? 'selected="selected' : '')>NEE</option>
</select>
<?php endif; ?>
Link gekopieerd
Mmm.. Ik krijg nog steeds een : syntax error, unexpected '<' in C:\xampp\htdocs\cmdb2\config2.php on line 133
<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>
Link gekopieerd
?
Onbekende gebruiker
19-06-2015 11:35
oke maar post je document of iets want wij zien line 132 niet.
Er zal iets niet goed worden afgesloten ofzo
Link gekopieerd
Oké, hier is het hele document:
<!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>
Link gekopieerd
?
Onbekende gebruiker
19-06-2015 12:00
Kijk eens aan.
<!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>
Link gekopieerd
Ik heb het script even uitgeprobeerd en krijg nu de volgende error:
Link gekopieerd