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

  1. there no function define in getdbconnect()
  2. if confusing 'and " split functions

    $id = $_request['crew_id']; $sql = "delete crewlist id = '$id' "; 
  3. use mysqli_query , mysqli_error in correct format

  4. and error in mysqli_query, not passing connection mysqli
  5. when ever database part finished, close connection mysqli_close($conn);

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -