带有空值检查的PHP Update脚本

时间:2017-02-23 08:20:00

标签: php database pdo

我使用空值检查得到了这个PHP脚本。 但由于某些原因,当我在TD中添加超链接时,它不再更新我的值。

你能帮帮我吗?

edit.php

<?php
require_once('connect.php');

$newKenteken = $_POST['kenteken'];
$newMerk = $_POST['merk'];
$newType = $_POST['type'];
$newBouwjaar = $_POST['bouwjaar'];
$newTenaamstellingdatum = $_POST['tenaamstellingdatum'];
$newGewicht = $_POST['gewicht'];
$newToelatingdatum = $_POST['toelatingdatum'];
$newAfgiftedatum = $_POST['afgiftedatum'];
$id = $_POST['memids'];

if ( empty($kenteken) || empty($merk) || empty($type) || empty($bouwjaar) || empty($tenaamstellingdatum) || empty($gewicht) || empty($toelatingdatum) || empty($afgiftedatum) ) {
		echo "U bent wat vergeten in te vullen of u heeft niks ingevuld.";
		header("refresh: 3; url=index.php");
	} else {
		$sql = "UPDATE voertuig 
				SET kenteken=?, merk=?, type=?, bouwjaar=?, tenaamstellingdatum=?, gewicht=?, toelatingdatum=?, afgiftedatum=?
				WHERE vid=?";
		$q = $db->prepare($sql);
		$q->execute(array($newKenteken,$newMerk,$newType,$newBouwjaar,$newTenaamstellingdatum,$newGewicht,$newToelatingdatum,$newAfgiftedatum,$id));
		header("location: index.php");
	}
?>

editform.php

<?php
	require_once('connect.php');
	require_once('navi.php');
	require_once('style.css');
	$id=$_GET['id'];
	$result = $db->prepare("SELECT * FROM voertuig WHERE vid= :id");
	$result->bindParam(':id', $id);
	$result->execute();
	for($i=0; $row = $result->fetch(); $i++){
?>
	<form action="edit.php" method="POST">
		<input type="hidden" name="memids" value="<?php echo $id; ?>" />
		Kenteken<br>
		<input type="text" name="kenteken" value="<?php echo $row['kenteken']; ?>" /><br>
		Merk<br>
		<input type="text" name="merk" value="<?php echo $row['merk']; ?>" /><br>
		Type<br>
		<input type="text" name="type" value="<?php echo $row['type']; ?>" /><br>
		Bouwjaar<br>
		<input type="text" name="bouwjaar" value="<?php echo $row['bouwjaar']; ?>" /><br>
		Tenaamstellingdatum<br>
		<input type="date" name="tenaamstellingdatum" value="<?php echo $row['tenaamstellingdatum']; ?>" /><br>
		Gewicht<br>
		<input type="text" name="gewicht" value="<?php echo $row['gewicht']; ?>" /><br>
		Toelatingdatum<br>
		<input type="date" name="toelatingdatum" value="<?php echo $row['toelatingdatum']; ?>" /><br>
		Afgiftedatum<br>
		<input type="date" name="afgiftedatum" value="<?php echo $row['afgiftedatum']; ?>" />
		<input type="submit" value="Save" />
	</form>
<?php
	}
?>

table_voertuig.php

<table border="1" cellspacing="0" cellpadding="2" >
<thead>
	<tr>
		<th> Kenteken </th>
		<th> Merk </th>
		<th> Type </th>
		<th> Bouwjaar </th>
		<th> Tenaamstellingdatum </th>
		<th> Gewicht </th>
		<th> Toelatingdatum </th>
		<th> Afgiftedatum </th>
	</tr>
</thead>
<tbody>
	<?php
		require_once('connect.php');
		$result = $db->prepare("SELECT * FROM voertuig ORDER BY vid DESC");
		$result->execute();
		for($i=0; $row = $result->fetch(); $i++){
	?>
	<tr class="record">
		<td><a href="editform.php?id=<?php echo $row['vid']; ?>"><?php echo $row['kenteken']; ?></a></td>
		<td><?php echo $row['merk']; ?></td>
		<td><?php echo $row['type']; ?></td>
		<td><?php echo $row['bouwjaar']; ?></td>
		<td><?php echo $row['tenaamstellingdatum']; ?></td>
		<td><?php echo $row['gewicht']; ?></td>
		<td><?php echo $row['toelatingdatum']; ?></td>
		<td><?php echo $row['afgiftedatum']; ?></td>
	</tr>
	<?php
		}
	?>
</tbody>
</table>

0 个答案:

没有答案