国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP native development news station deleting news

Our first two articles have completed the addition and modification of news. So in this lesson, we will introduce you to deleting news. This one is simpler than the previous two!

First create a new_delete.php, then we need to find the delete button on the news list page and add a connection to this button. We also need to transmit data through the id and delete the news based on the id, but here we Still use JS

<a class='button border-red' href='javascript:;' onclick='return del(<?php echo $val['id']?>)'>
<span class='icon-trash-o'></span> 刪除</a>

Then add a JS code at the bottom of the news list page:

//單個(gè)刪除
function del(id){
    if(confirm("您確定要?jiǎng)h除嗎?")){
        document.location.href = "new_delete.php?id=" + id ;
    }
}

Then we introduce the passed data through the id on the new_delete.php page, and then the most data deal with!

Needless to say, the first step is to connect to the database:

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/2
 * Time: 15:44
 */
// 連接mysql數(shù)據(jù)庫
$link = mysqli_connect('localhost', 'root', 'root');
if (!$link) {
    echo "connect mysql error!";
    exit();
}

// 選中數(shù)據(jù)庫 my_db為數(shù)據(jù)庫的名字
$db_selected = mysqli_select_db($link, 'news');
if (!$db_selected) {
    echo "<br>selected db error!";
    exit();
}

The next step is to accept the ID data, then query the data based on the ID, execute the SQL statement,

$id = $_GET['id'];
if( !is_numeric($id) ){
    echo "ERROR!";
    exit;
}
$sql = "delete from new where id = $id";
$result = mysqli_query($link, $sql);

The last step is to delete the data :

if($result){
    echo "刪除成功!";
    // 直接跳轉(zhuǎn)進(jìn)入簡(jiǎn)歷列表
    header("Location: new_list.php");

} else {
    echo "刪除失敗!";
}

Isn’t it very simple? The deletion function is now complete!


Continuing Learning
||
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/9/2 * Time: 15:44 */ // 連接mysql數(shù)據(jù)庫 $link = mysqli_connect('localhost', 'root', 'root'); if (!$link) { echo "connect mysql error!"; exit(); } // 選中數(shù)據(jù)庫 my_db為數(shù)據(jù)庫的名字 $db_selected = mysqli_select_db($link, 'news'); if (!$db_selected) { echo "<br>selected db error!"; exit(); } // 根據(jù)id 刪除 $id = $_GET['id']; if( !is_numeric($id) ){ echo "ERROR!"; exit; } $sql = "delete from new where id = $id"; // 執(zhí)行sql語句 $result = mysqli_query($link, $sql); if($result){ echo "刪除成功!"; // 直接跳轉(zhuǎn)進(jìn)入簡(jiǎn)歷列表 header("Location: new_list.php"); } else { echo "刪除失敗!"; }
submitReset Code