PHP MySQL Call to a member function execute() on a non-object -


i got error when prepare $query. here lines :

$query="insert bm(title,season) values(:title, :season)"; $stmt = $mysqli->prepare($query); //$stmt->bind_param("ss", $title, $season); $stmt->execute(array(':title' => $title, ':season' => $season)); 

i put line bind_param in // saw on others solve error became same :

fatal error: call member function bind_param() on non-object

so, thought of query it's simple can't see anymore clearly. it's driving me nuts. :-/ tested var $titleand $season echo before $query line sure, :

echo $title." et ".$season; 

but nothing wrong, values ok. these strings var. appreciated. thanks.


here complete code :

<?php include("connexion.php");  // vars previous form  //$id=""; $title = isset($_post['title']) ? $_post['title'] : ""; $season = isset($_post['season']) ? $_post['season'] : "";  // testing vars  if (empty($titre) && empty($saison))     {      echo '<font color="red">must filled...</font>';     }  // vars ok : inserted in "bm" table else      {        // protect - inject sql        $title=$mysqli->real_escape_string(strip_tags($title));        $season=$mysqli->real_escape_string(strip_tags($season));         // test        echo $title." et ".$season;         // insert method         $query="insert bm(title,season) values(:title, :season)";        $stmt = $mysqli->prepare($query);        $stmt->bind_param("ss", $title, $season);        $stmt->execute(array(':title' => $title, ':season' => $season));         // insert ok ?     if ($stmt)  {             echo "insert ok.";       }        else   {             echo "insert failed !";         }     }  //close connexion      $mysqli->close(); ?> 

try change database call follows:

$query="insert bm(title,season) values(?, ?)"; $stmt = $mysqli->prepare($query); //could false if prepared statemant somehow wrong if ($stmt === false){     echo "insert failed !"; } else{     //bind params variables     $stmt->bind_param("ss", $title, $season);     //no parameters allowed execute method according doc     $success = $stmt->execute();     //check $success if true/false } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -