skip to Main Content

The SQL query in the $sql works when I directly enter that in the phpmyadmin only replacing the ‘$movieid’ as 1

The code in the deletemovie.php:

    $delete = "Includes/deletemovierecord.php?id=$movieid";
    echo "
    <tr>
    <td>$movieid</td>
    <td>$moviename</td>
    <td>$year</td>
    <td>$genere</td>
    <td>$stock</td>
    <td>
     <form action='Includes/updatemoviestock.php?key=$stock&id=$movieid' 
      method='post'>
       <input type='text' name='newstock'>
       <input type='submit' value='Add' id='stock' name='update'>
     </form>
    </td>
    <td><a href=$delete id='delete'>Delete</a></td>
    </tr>
    ";

The code in the deletemovierecord.php:

<?php
include "databaseconn.php";
$movieid = $_GET['id'];
$sql = "DELETE FROM movies WHERE movieid = '$movieid'";
$query = mysqli_query($conn, $sql);

if($query){
    header('location: ../admin.php');
}
else{
    echo "error";
}

?>

4

Answers


  1. ex :

    $sql = "DELETE FROM movies WHERE movieid = ".$movieid; //if movieid is integer
    

    ex2: $sql = "DELETE FROM movies WHERE movieid = '{$movieid}' ";

    Login or Signup to reply.
  2. You have just created a variable here:

    $delete = "Includes/deletemovierecord.php?id=$movieid";
    

    You need to execute it. You need to include that but execute it too. Either make a cURL request or do an AJAX call to the above URL. Even include won’t work in this case:

    include($delete);
    

    Because the $_GET will not be activated here.

    Login or Signup to reply.
  3. It might be that $movieid is not replaced by its value. Try to change $sql:

    $sql = "DELETE * FROM movies WHERE movieid = ".$movieid.";";
    

    You are now concatenating three strings, where the actual value of $movieid is filled into the place where it has to.

    Login or Signup to reply.
  4. It seems that you are not passing the variable $movieid to the php script.

    You need to replace

    <a href=$delete id='delete'>
    

    With

    <a href="Includes/deletemovierecord.php?id=$movieid" id='delete'>
    

    in deletemovie.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search