21,886
社区成员
发帖
与我相关
我的任务
分享
if(isset($_POST['action']) and $_POST['action']=='Edit'){
try {
$sql='SELECT id,name FROM category WHERE id= :id';
$s=$pdo->prepare($sql);
$s->bindValue(':id', $_POST['id']);
$s->execute();
}catch (PDOException $e){
$error='编辑失败'.$e->getMessage();
include 'error.html.php';
exit();
}
$row=$s->fetch();
var_dump($row);////////////////////////////////测试失败,为什么这个row没值??///////////////////
$pageTitle='编辑分类';
$action='editform';
$name=$row['name'];
$id=$row['id'];
$button='Edit';
include 'form.html.php';
exit();
}
if (isset($_get['editform'])){
try{
$sql='UPDATE category SET name=:name WHERE id=:id';
$s=$pdo->prepare($sql);
$s->bindValue(':name', $_POST['name']);
$s->bindValue(':id', $_POST['id']);
$s->execute();
}catch (PDOException $e){
$error='更新失败'.$e->getMessage();
include 'error.html.php';
exit();
}
header('Location:.');
exit();
}
<?php
include $_SERVER['DOCUMENT_ROOT'].'/text/includes/helpers.inc.php';
?>
<html>
<meta charset="utf-8"/>
<head>
<title>Manage Categories</title>
</head>
<body>
<h1>Manage Categories</h1>
<p><a href="?add">Add NEW category</a></p>
<ul>
<?php foreach ($categories as $category):?>
<li>
<form action="" method="post">
<div>
<?php htmlout($category['name'])?>
<input type="hidden" name="id" value="<?php $category['id']?>" />
<input type="submit" name="action" value="Edit" />
<input type="submit" name="action" value="Delete" />
</div>
</form>
</li>
<?php endforeach;?>
</ul>
<p><a href="..">返回管理界面</a></p>
</body>
</html>
<?php
include $_SERVER['DOCUMENT_ROOT'].'/text/includes/helpers.inc.php';
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title><?php htmlout($pageTitle);?></title>
</head>
<body>
<h1><?php htmlout($pageTitle)?></h1>
<form action="?<?php htmlout($action)?>" method="post">
<div>
<label for="name">分类名称: <input type="text" name="name" id="name" value="<?php htmlout($name);?>" /></label>
</div>
<div>
</div>
<input type="hidden" name="id" value="<?php htmlout($id)?>" />
<input type="submit" value="<?php htmlout($button)?>" />
</form>
</body>
</html>