0
$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>";

I keep getting an error stating that the index id is not found.. I tried everything but it won't delete that specific row. I have a database with movies and the idea is that when the user clicks the "Obriši" button the selected movie gets deleted from the database "kolekcija". But it won't work? Can you please advise..?

  • Is `$_GET ["id"]` set, and does it contain a valid ID? (Hint: You're not doing any input validation or anything to protect your database from invalid input, so apart from anything else you're wide open to SQL injection! I could set $id to `"';--DROP TABLE filmovi"` and ruin your day) – GordonM Jan 05 '17 at 17:24
  • 4
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 05 '17 at 17:24
  • You might have passed the wrong parameters to the script. Please try using: `print_r($_GET);` or `print_r($_POST);` and check out whether the variable is correctly created. – Gautam Krishna R Jan 05 '17 at 17:29

0 Answers0