php简单美工程序分离,内容编辑实例...
时间:2010-08-13 来源:linwins
if($_POST['op'] == 'edit') {
$sql = "
UPDATE " . TABLE_PREFIX . "user
SET
name = '" . $_POST['name'] . "',
birthday = '" . $_POST['birthday'] . "',
email = '" . $_POST['email'] . "',
sex = '" . $_POST['sex'] . "'
WHERE
id = '" . $_POST['id'] . "'
";
if(db_exec($sql)) {
$notice = array(
'msg' => '修改成功',
'alt' => '列表用户',
'url' => '?op=index'
);
require_once 'view/_notice.phtml';
} else {
$notice = array(
'msg' => '修改失败',
'alt' => '修改用户',
'url' => '?op=edit&id=' . $_POST['id']
);
require_once 'view/_notice.phtml';
}
} else {
$sql = "
SELECT *
FROM ". TABLE_PREFIX . "user
WHERE id = '". (int)$_GET['id'] ."' ";
$data = fetch($sql);
require_once 'www.111cn.net/edit.phtml';
}
edit.phtml代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户编辑</title>
</head>
<body>
<h3>用户编辑</h3>
<form action="?op=edit" method="post" enctype="application/x-www-form-urlencoded">
姓名:<input type="text" name="name" size="15" value="<?php echo $data['name'] ?>" /><br />
生日:<input type="text" name="birthday" size="10" value="<?php echo $data['birthday'] ?>" /> (YYYY-MM-DD)<br />
邮箱:<input type="text" name="email" size="30" value="<?php echo $data['email'] ?>" /><br />
性别:<input type="radio" name="sex" value="3"<?php if($data['sex'] == '-') : ?> checked="checked"<?php endif; ?> />保密
<input type="radio" name="sex" value="1"<?php if($data['sex'] == 'M') : ?> checked="checked"<?php endif; ?> />男
<input type="radio" name="sex" value="2"<?php if($data['sex'] == 'F') : ?> checked="checked"<?php endif; ?> />女<br />
<input type="hidden" name="id" value="<?php echo $data['id'] ?>" />
<input type="hidden" name="op" value="edit" /><br />
<input type="submit" name="submit" value="编辑用户www.111cn.net" />
</form>
<?php require_once 'view/_foot.phtml'; ?>
</body>
</html>