如何使用mysql删除php中的特定行?

时间:2017-01-05 17:19:50

标签: php mysql

$msg = "";



$sql = "SELECT slika, naziv_filma, godina, trajanje FROM filmovi";
$myData = mysql_query($sql);
echo "<table border = '1'>
<tr>
<th>Slika</th><th>Naziv filma</th><th>Godina</th><th>Trajanje</th><th>Akcija</th></tr>";
while($record = mysql_fetch_array($myData))
    {
    echo "<form action = 'unos.php' method = 'post' enctype='multipart/form-data'>";
    echo "<tr>";
    echo "<td>" . $msg.= '<img src="data:image/jpeg;base64,'.base64_encode($record['slika']) .'"/>' . "</td>";
    echo "<td>" . $record['naziv_filma'] . "</td>";
    echo "<td>" . $record['godina'] . "</td>";
    echo "<td>" . $record['trajanje'] . "</td>";
    echo '<td><a href="unos.php?id='.$record['id'].'">Obriši</a></td>';

    if(isset($_GET['delete']))
        {
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = '';
            $conn = mysql_connect($dbhost, $dbuser, $dbpass);

            $id = $_GET['id'];
            $sql = "DELETE FROM filmovi WHERE id = '".$id."'" ;
            mysql_select_db('kolekcija');
            $retval = mysql_query( $sql, $conn );
            header("Location: unos.php");
        }
    echo "<input type = 'hidden' name = 'id' value = 'id' />";
    }

    echo "</tr>";
    echo "</form>";


echo "</table>";

我一直收到一条错误,指出找不到索引ID。我尝试了所有内容,但它不会删除该特定行。我有一个带电影的数据库,其想法是,当用户点击“Obriši”按钮时,所选电影将从数据库“kolekcija”中删除。但它不会起作用?能告诉你吗??

0 个答案:

没有答案