Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having issues with my delete file. I think I am missing something. The code

ID: 3554434 • Letter: I

Question

I am having issues with my delete file. I think I am missing something. The code does work because I have used it on other pages. Pasted below is my code along with code creating the table:

deletemovie.php

<head>
<title>Delete a Movie</title>
</head>
<body>
<h3>
<?php
$cm=mysqli_connect("localhost","censored", "censored", "censored");

if (mysqli_connect_errno())
{
echo "Cannot connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST['IMDB_ID'])){
  
   $movie = $_POST['IMDB_ID'];
   mysqli_query($cm, "DELETE FROM Movies WHERE IMDB_ID = $movie");
}
   mysqli_close($cm);


echo "The movie has been deleted from the table.";
echo "<br>";
?>
<a href="displaymovie.php">Go back to movie page</a>
</h3>
</body>
</html>

createmovie.php

<html>
<head>
<title>Movies Table</title>
</head>
<body>
    <h2>
   <?php
       $cm=mysqli_connect("localhost","censored","censored","censored");

           if (mysqli_connect_errno())
               {
               echo "Cannot connect to MySQL: " . mysqli_connect_error();
               }


       $sql = "CREATE TABLE Movies (IMDB_ID CHAR(10) NOT NULL,TITLE CHAR(100),RATING CHAR(5),PRIMARY KEY(IMDB_ID)) ";

  
           if (mysqli_query($cm,$sql))
           {
               echo "Table created successfully";
           }
           else
            {
               echo "There was an error in creating table: " . mysqli_error($cm);
           }
    ?>
<a href="insertmovie.php">Generate Table</a>
</body>
</html>

Explanation / Answer

The IMDB_ID is text (char (10)) which must be written in single quotes ( ' ). The query should be

"DELETE FROM Movies WHERE IMDB_ID = ' ". $movie . " ' "

I have given spaces between single and double quotes for clear understanding which should be removed in the query while executing.