mysqli neden bu durumda nedir?

3 Cevap php

Ben sonraki iki mysqli ifadeleri ve ikinci getiri:

Ölümcül hata: olmayan bir nesne üzerinde bir üye işlev bind_param () Çağrı ...

Why this happens? Does this means that I need to open two different connection? Is there any way to avoid this (I love keeping the SQL connection details in one file)?

İşte kod:

$db = new mysqli("localhost", "root", "", "database");

$stmt = $db->prepare("UPDATE posts SET vote_".$_POST['vote']." = vote_".$_POST['vote']." + 1 WHERE id=?");
$stmt->bind_param('s', $_POST['id_post']);
$stmt->execute();
$stmt->close();

$stmt = $db->prepare("INSERT INTO votes (kind, users_id, posts_id) VALUES (?, ?, ?)");
$stmt->bind_param('sss',$_POST['vote'],$_POST['id_user'],$_POST['id_post']);
$stmt->execute();
$stmt->close();

3 Cevap

Dönüş değerini kontrol mysqli::prepare. FALSE ise, mysqli::error ile Oluştu hata ayrıntılarını almalısınız.

Ben bunun üzerinde bind_param aradığınızda $ deyim değişkeni boş olduğunu düşünüyorum. belki $ _POST ['oy'] boş? Eğer komuta param bağlamak önce bunu kontrol edebilirsiniz

Something $db->prepare(), çek ile yanlış gitmiş olabilir $db->error.