Solomon Closson
Solomon Closson

Reputation: 6217

How do I bind this 1 variable using mysqli?

Ok, so I have been at this for hours now, and no matter what i do, it just doesn't work. I've read pages of documentation and even tried verbatim by examples, and still doesn't work:

$db = mysqli_connect($db_server, $db_user, $db_passwd, $db_name);

if (mysqli_connect_errno())
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$db_query = "SELECT ca.id_article, ca.title, ca.body, ca.id_tag, ca.visible, ct.title AS tag_title
            FROM cdfi_articles AS ca
            INNER JOIN cdfi_tags AS ct ON(ct.id_tag = ca.id_tag)
            WHERE ca.id_article = ?
            LIMIT 1";
;
if ($stmt = mysqli_prepare($db, $db_query)) {
    mysqli_stmt_bind_param($stmt, "i", $_REQUEST['article']);

    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $return);
    mysqli_stmt_fetch($stmt);

    var_dump($return);

}

mysqli_close($db);

The following error occurs and I don't know how to fix it at all:

Warning: mysqli_stmt_bind_result() [function.mysqli-stmt-bind-result]: Number of bind variables doesn't match number of fields in prepared statement in ... filepath on line {line number}

bind variables don't match? I am only using 1 variable, and only 1 question mark within the query, what gives??

var_dump($return) returns NULL value

How can I fix this? I just want to get that 1 row returned within the $return variable so that I can do something with it, arggg!

Upvotes: 2

Views: 143

Answers (1)

dnagirl
dnagirl

Reputation: 20456

You are selecting 6 columns but you are only binding $return in mysqli_stmt_bind_result($stmt, $return);

Try

mysqli_stmt_bind_result($stmt, $artid, $title, $body, $tagid, $vis, $tagtitle );

Upvotes: 3

Related Questions