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
ex :
ex2:
$sql = "DELETE FROM movies WHERE movieid = '{$movieid}' ";
You have just created a variable here:
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:Because the
$_GET
will not be activated here.It might be that $movieid is not replaced by its value. Try to change $sql:
You are now concatenating three strings, where the actual value of $movieid is filled into the place where it has to.
It seems that you are not passing the variable $movieid to the php script.
You need to replace
With
in deletemovie.php