php-删除数据库中的数据

html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$Title$title>
head>
<body>
<h1>Delete an Entryh1>
    $dbc = mysql_connect('localhost','username','password');
    mysql_select_db('myblog',$dbc);
    if(isset($_GET['id']) && is_numeric($_GET['id'])){  //在表单中显示条目:
        //定义查询:
        $query = "SELECT title,entry FROM entries WHERE entry_id={$_GET['id']}";
        if($r = mysql_query($query,$dbc)) {  //运行查询。
            $row = mysql_fetch_array($r);   //返回信息。

            //创建表单:
            echo '

Are you sure you want to delete this entry?

'.$row['title'].'

'
.$row['entry'].'
.$_GET['id'].'"/>

'
; }else{ //无法获取信息。 echo '

Could not retrieve the blog entry because:
'. mysqli_error($dbc).'.

The query being run was:'.$query.'

'
; } }elseif (isset($_POST['id']) && is_numeric($_POST['id'])){ //处理表单。 //定义查询: $query = "DELETE FROM entries WHERE entry_id = {$_POST['id']} LIMIT 1"; $r = mysql_query($query,$dbc); //执行查询。 //检查查询结果: if(mysqli_affected_rows($dbc) == 1){ echo '

The blog entry has been deleted.

'
; }else{ echo '

Could not delete the blog entry because:
'. mysql_error($dbc).'.

The query being run was:'.$query.'

'
; } }else{ //没有获取id。 echo '

This page has been accessed in error.

'
; } //结束条件语句。 mysql_close($dbc); //关闭连接。 ?> body> html>

你可能感兴趣的:(php-删除数据库中的数据)