当我单击按钮时,我想从数据库中删除3个字段:fk_id_bandid_bandband

但是我无法将mysql查询从我的PHP文件发送到数据库。

我有这个PHP代码:

<?php
    session_start();
    include('database.php');

    $id = $_SESSION['id'];

    $select = "SELECT *
    FROM users
    WHERE id_user = ".$id."";

    $result = mysql_query($select);

    $line = mysql_fetch_assoc($result);

    $idband = $line["fk_id_band"];


    $sqldelete = "DELETE bands
    FROM bands
    WHERE id_band = ".$idband."";

    echo $sqldelete;

    mysql_query($sqldelete);
?>


当我在phpmyadmin中插入查询时,它可以工作。 (DELETE bands FROM bands WHERE id_band = 1)

但是,当我使用mysql_query($sqldelete)时,它不会像我认为的那样自动更新数据库。

怎么了

最佳答案

您的删除语句中有语法错误

$id = $_SESSION['id'];

$select = "select * from users WHERE ID = $id";
$result = mysql_query($select);
$line = mysql_fetch_assoc($result);

 $idband = $line["fk_id_band"];
 $sqldelete = "DELETE bands
 FROM bands
WHERE id_band = ".$idband;
echo $sqldelete;

mysql_query($sqldelete);

10-04 13:26