PHP? ??? ?? ??? ??? ?? ?? ???? ?????.
?? ?? ?? ??? ??? ?? ?? ??? ??????.
?? ?? ???? ?? ???? "??"? ???? ?? ?? ???? ?? ?????.
<body> <a href="edit.php?id=<?php echo $arr['id']?>"><font color="red">修改</font></a> </body>
??? ?? ?? ???? edit.php???. "Edit"? ???? ? ??? id ?? ?? ?? ?? ???? ?????.
$_GET? ???? ID? ?????. ?? ?? ???? ????, ???? <form> ???? ?????? ?? ?? ?? ?? ???? ??? ?????.
<?php $id = isset($_GET["id"])?$_GET["id"]:""; ?>
SQL ?? ??? ????.
<?php $sql="select id,title,author,content from new where id = '$id'"; $rel = mysqli_query($link,$sql);//執(zhí)行sql語(yǔ)句 $arr= mysqli_fetch_array($rel); //獲取一條新聞的所有信息 ?>
POST? ?? ??, ???, ??? ?????
<?php $title = isset($_POST['title'])?$_POST['title']:""; //獲取標(biāo)題 $author = isset($_POST['author'])?$_POST['author']:""; //獲取作者 $content = isset($_POST['content'])?$_POST['content']:""; //獲取內(nèi)容 ?>
?? ??? HTML ???? ?????
<body> <form name="article" method="post" action="update.php" style="margin:5px;"> <h1>新聞修改頁(yè)</h1> <input type="hidden" name="id" value="<?php echo $arr['id']?>"/><br/> 標(biāo) 題:<input type="text" name="title" value="<?php echo $arr['title']?>"/><br/><br/> 作 者:<input type="text" name="author" value="<?php echo $arr['title']?>"/><br/><br/> <span>內(nèi) 容:</span> <textarea cols=30 rows=5 name="content"><?php echo $arr['content']?></textarea><br/><br/> <input type="submit" value="修改新聞"/> </form> </body>
??? ?? "??"? ???? ?? ?? ???? ?? ??? ???? HTML ???? ?????.
?? ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>新聞修改頁(yè)面</title> <style type="text/css"> span{display:inline-block; float: left; width: 50px;} input[type="submit"]{margin-left: 10%;} </style> </head> <body bgcolor="#ccc"> <?php $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } $id = isset($_GET["id"])?$_GET["id"]:""; $title = isset($_POST['title'])?$_POST['title']:""; $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; $sql="select id,title,author,content from new where id = '$id'"; //echo $sql; $rel = mysqli_query($link,$sql);//執(zhí)行sql語(yǔ)句 $arr= mysqli_fetch_array($rel); ?> <form name="article" method="post" action="update.php" style="margin:5px;"> <h1>新聞修改頁(yè)</h1> <input type="hidden" name="id" value="<?php echo $arr['id']?>"/><br/> 標(biāo) 題:<input type="text" name="title" value="<?php echo $arr['title']?>"/><br/><br/> 作 者:<input type="text" name="author" value="<?php echo $arr['title']?>"/><br/><br/> <span>內(nèi) 容:</span> <textarea cols=30 rows=5 name="content"><?php echo $arr['content']?></textarea><br/><br/> <input type="submit" value="修改新聞"/> </form> </body> </html>