PHP? ??? ?? ??? ???? ???? ?? ?? ??? ??? ?????.
?? ????? PHP? ???? ??? ?? ??? ???? ?? ?? ???? ???? ?? ?? ???
?? "??"? ???? ?? ?? ???? ?? ???? ??? ???? ??? ??????.
? ????? PHP ??? ?? ?? ?? ???? ?? ? ?? ??? ???? ??? ?????.
?? ?????? ???? ? ???? ???? ???.
<?php $link = mysqli_connect('localhost','uesename','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } ?>
POST? ???? ?? ?????. ????? ??, ???, ?? ???
<?php $id = isset($_POST['id'])?$_POST['id']:""; //獲取id的值 $title = isset($_POST['title'])?$_POST['title']:""; $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; ?>
?? ????? ?????. SQL ? : ??? ?? ??? ??? ? ??? ???? ????
<?php $sql="update new set title = '$title',author = '$author',content = '$content' where id = '$id'"; //echo $sql; $rel=mysqli_query($link,$sql);//執(zhí)行sql語句 //echo $rel ?>
update.php ?? ??:
<?php header("content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } $id = isset($_POST['id'])?$_POST['id']:""; $title = isset($_POST['title'])?$_POST['title']:""; $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; $sql="update new set title = '$title',author = '$author',content = '$content' where id = '$id'"; //echo $sql; $rel=mysqli_query($link,$sql);//執(zhí)行sql語句 //echo $rel if($rel){ echo "<script>alert('新聞修改成功');window.location.href='list.php'</script>"; }else{ echo "<script>alert('新聞修改失敗');window.location.href='edit.php'</script>"; } ?>
?? PHP? ??? ??? ?? ??? ???? ??? ?????. ???? ? ?? ?? ???? ?? ???? ??? ??? ?? ?? ???? ??, ??, ??, ??? ? ?? ??? ???? ??? ?? ? ????.
??: ? ?? ??? ??? ??? ??? ?? ???? ??? ?????? ?? ??? ? ????.