php - SQL Delete statement not working -
include_once 'dbfunction.php'; getdbconnect(); mysqli_query("delete crewlist id = $_get[crew_id]") or die (mysqli_error()); echo 'delete success'; header ('location: crewlisting.php');
this code doesn't work, when replace crew_id actual primary key via hard coding delete function works
use (mysqli procedural
)
in dbfunction.php
should be
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "mydb"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn) { die("connection failed: " . mysqli_connect_error()); } ?>
and insert page should be
<? include ("dbfunction.php"); //include db connection $id = $_request['crew_id']; $sql = "delete crewlist id = '$id' "; if (mysqli_query($conn, $sql)) { echo "record deleted successfully"; } else { echo "error deleting record: " . mysqli_error($conn); } mysqli_close($conn); ?>
errors are
- there no function define in
getdbconnect()
if confusing
'
and"
split functions$id = $_request['crew_id']; $sql = "delete crewlist id = '$id' ";
use
mysqli_query
,mysqli_error
in correct format- and error in
mysqli_query
, not passing connectionmysqli
- when ever database part finished, close connection
mysqli_close($conn);
Comments
Post a Comment