PHP로 개발된 뉴스 관리 시스템의 수정 기능 구현(1부)

이전 섹션에서 데이터베이스의 정보가 표시되었다고 언급했습니다. 두 개의 연결을 수정하고 삭제할 때 id

<a href="modifynew.php?id를 출력하는 명령문을 작성했다는 사실을 알고 계셨나요? =<? php echo $row['id'];?>">수정</a>

<a href="delnew.php?id=<?php echo $row['id' ];?>">삭제</a>

수정, ID를 가져와서 ID를 기반으로 데이터에서 쿼리한 다음 ID의 다른 필드 내용을 수정해야 합니다. 다음 수정된 내용을 살펴보겠습니다. flow Chart

md.png

수정하려면 id가 수정new.php 파일로 전송됩니다.

이 페이지는 수정된 페이지입니다.

104.png

이 페이지에는 다음이 필요합니다. 방금 전달한 ID를 기반으로 진행합니다. 데이터베이스에 쿼리한 다음 제목 내용을 표시합니다

먼저 데이터베이스에 연결합니다:

header("Content-type: text/html; charset=utf-8");// 인코딩 설정
$con =@mysql_connect("localhost ","root","root") 또는 die("데이터베이스 연결 실패");
mysql_select_db('news') 또는 die("지정된 데이터베이스를 열 수 없습니다." );
mysql_query("set names utf8");/ /데이터베이스의 문자 집합을 설정

한 다음 ID를 얻습니다

양식의 ID 우리는 get 메소드를 사용하여

$id=$_GET를 얻습니다. ['id'];

ID를 기준으로 데이터베이스를 쿼리합니다

$sql ="select * from new where id=$id";
$res = mysql_query($sql);
$row = mysql_fetch_array($ res);

정보를 쿼리한 후 페이지에 정보를 표시해야 합니다

html 페이지의 코드는 다음과 같습니다.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
    *{margin:0px;padding:0px;}
    body{background:#ccc;}
    .add{width:450px;height:280px;background:#eee;float:left;}
    .cont{width:500px;height:350px;margin-top:5px;margin-left:5px;}
    form{margin-left:10px;padding-top:30px;}
    .sub{width:100px;height:40px;border:1px solid #ccc;}
    .sub:hover{background:#f90}
    </style>
</head>
<body>
    <div class="add">
        <div class="cont">
            <form method="post" action="modify.php?id=<?php echo $id;?>">
                标题:<input type="text" name="title" value="<?php echo $row['title']?>"></br></br>
                内容:<textarea cols="50" rows="5" name="content"><?php echo $row['content']?></textarea></br></br>
                <input type="submit" value="修改" class="sub">
            </form>
        </div>
    </div>
</body>
</html>

이렇게 하면 데이터베이스에서 쿼리한 정보가 표시됩니다


전체 소스 코드는 다음과 같습니다:

<?php
    header("Content-type: text/html; charset=utf-8");//设置编码
    $con =@mysql_connect("localhost","root","root") or die("数据库连接失败");
    mysql_select_db('news') or die("指定的数据库不能打开");
    mysql_query("set names utf8");//设置数据库的字符集

    $id=$_GET['id'];
    $sql="select * from new 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">
    *{margin:0px;padding:0px;}
    body{background:#ccc;}
    .add{width:450px;height:280px;background:#eee;float:left;}
    .cont{width:500px;height:350px;margin-top:5px;margin-left:5px;}
    form{margin-left:10px;padding-top:30px;}
    .sub{width:100px;height:40px;border:1px solid #ccc;}
    .sub:hover{background:#f90}
    </style>
</head>
<body>
    <div class="add">
        <div class="cont">
            <form method="post" action="modify.php?id=<?php echo $id;?>">
                标题:<input type="text" name="title" value="<?php echo $row['title']?>"></br></br>
                内容:<textarea cols="50" rows="5" name="content"><?php echo $row['content']?></textarea></br></br>
                <input type="submit" value="修改" class="sub">
            </form>
        </div>
    </div>
</body>
</html>


지속적인 학습
||
<?php header("Content-type: text/html; charset=utf-8");//设置编码 $con =@mysql_connect("localhost","root","root") or die("数据库连接失败"); mysql_select_db('news') or die("指定的数据库不能打开"); mysql_query("set names utf8");//设置数据库的字符集 $id=$_GET['id']; $sql="select * from new 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"> *{margin:0px;padding:0px;} body{background:#ccc;} .add{width:450px;height:280px;background:#eee;float:left;} .cont{width:500px;height:350px;margin-top:5px;margin-left:5px;} form{margin-left:10px;padding-top:30px;} .sub{width:100px;height:40px;border:1px solid #ccc;} .sub:hover{background:#f90} </style> </head> <body> <div class="add"> <div class="cont"> <form method="post" action="modify.php?id=<?php echo $id;?>"> 标题:<input type="text" name="title" value="<?php echo $row['title']?>"></br></br> 内容:<textarea cols="50" rows="5" name="content"><?php echo $row['content']?></textarea></br></br> <input type="submit" value="修改" class="sub"> </form> </div> </div> </body> </html>
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!