PHP开发企业网站教程之修改关于我们信息

下面我们直接来看代码

<?php
    header("Content-type: text/html; charset=utf-8");//设置编码
    require_once('conn.php');
    $id = $_GET['id'];
    $sql = "SELECT * FROM about where id='$id'";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改信息</title>
    <style type="text/css">
        .ipt{width:180px;height:30px;border-radius:5px;
            outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;}
        .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;}
    </style>
</head>
<body>
    <form method="post" action="modifyabout.php?id=<?php echo $id;?>">
        标题:<input type="text" name="title" class="ipt" value="<?php echo $row['title'];?>">
        </br></br>
        内容:<textarea cols="80" rows="10" name="content" class="txt"><?php echo $row['content'];?></textarea></br></br>
        <input type="submit" value="修改" class="sub">
    </form>
</body>
</html>

处理修改页面 modifyabout.php

我们来看以下修改的页面的代码:

<?php
    require_once('conn.php');
    $id = $_GET['id'];
    $title = $_POST['title'];
    $content = $_POST['content'];

    $sql = "UPDATE about SET title='$title',content='$content' where id='$id'";
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('修改信息成功');location.href='about.php'</script>";
    }else{
        echo "<script>alert('修改信息失败');history.go(-1);</script>";
    }

?>


Weiter lernen
||
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
<?php
header("Content-type: text/html; charset=utf-8");//
require_once('conn.php');
$id = $_GET['id'];
$sql = "SELECT * FROM about where id='$id'";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.ipt{width:180px;height:30px;border-radius:5px;
outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;}
.sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;}
</style>
</head>
<body>
<form method="post" action="modifyabout.php?id=<?php echo $id;?>">
<input type="text" name="title" class="ipt" value="<?php echo $row['title'];?>">
</br></br>
<textarea cols="80" rows="10" name="content" class="txt"><?php echo $row['content'];?></textarea></br
     ></br>
<input type="submit" value="" class="sub">
</form>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
einreichenCode zurücksetzen
图片放大关闭