0

I have been stuck on this problem for a few days now and can't seems to work it out! I am trying to delete a blog entry where the title is posted to the form through sql and have tried 2 ways, both fail and give the following outputs/errors:

Test Inputstring(10) "Test Input" Fatal error: Call to a member function bind_param() on a non-object in 'FilePath' on line 163

This is the code including the other way I have tried:

$DelEntry = $_POST['postEntry']; 
echo $DelEntry;

//$query2 = "DELETE FROM Blog WHERE Title =\"" . $DelEntry . "\"";
//echo $query2;
//$result2 = mysqli_query($mysqli, $query2);

//if (!$result2) {
//die('Invalid query: ' . mysql_error());
//}

$stmt2 = $mysqli->prepare("DELETE FROM Blog WHERE Title = ?");
var_dump($DelEntry);
$stmt2->bind_param('s', $DelEntry);
$stmt2->execute(); 
$stmt2->close();
//header("Location: listall.php");  
exit; 

line 163 specifically is:

$stmt2->bind_param('s', $DelEntry);

Any help would really be appreciated, Thanks!

Thanks for the link @Qirel but none of those solutions have worked, I have closed all previous forms of $mysqli, attempted to enable PDOExceptions where its telling me it cannot be done on non-objects and I have checked that "DELETE FROM Blog WHERE Title = "Test Input"" does work with my database. Really stuck, any more help would be appreciated

  • 4
    Possible duplicate of [Call to a member function bind\_param() on a non-object](http://stackoverflow.com/questions/4488035/call-to-a-member-function-bind-param-on-a-non-object) – Qirel Feb 08 '16 at 14:54
  • It could be that `$_POST['postEntry']` is not set, and as such is being assigned `''`, use a check to see if it is set – Can O' Spam Feb 08 '16 at 14:54
  • Thanks for the link @Qirel but none of those solutions have worked, I have closed all previous forms of $mysqli, attempted to enable PDOExceptions where its telling me it cannot be done on non-objects and I have checked that "DELETE FROM Blog WHERE Title = "Test Input"" does work with my database. Really stuck, any more help would be appriciated – Josh Windsor Feb 08 '16 at 15:40
  • PDOExceptions wouldn't work with MySQLi anyway. The fact that `$stmt2` isn't an object, means that the prepare failed. Which means that the query failed. You said you closed the connection..? You can't close the entire connection if you want to use it ;-) – Qirel Feb 08 '16 at 15:45

0 Answers0