tags:

views:

46

answers:

2

I'm sure this will somebody no time at all.

I know that MySqli works on this server as i have tried inserts and they work fine.

I also know that the information I'm trying to obtain is in the database and i can connect to the database without any problems. But I can't for the life of me figure out why this isn't working. I've tried both OO and Procedural but neither of them work. Can someone tell me what it is i'm supposed to be doing? Thanks

$table = 'newcms_broadcasting';

$sql = "SELECT first_info1 FROM $table WHERE region_id = ?";

echo $sql;

//echo $sql;


$region = '1';

$stmt = mysqli_prepare($connection, $sql);

    mysqli_stmt_bind_param("s", $region);
    mysqli_execute();
    mysqli_bind_result($result);

    echo 'blah';

    // display the results
    mysqli_fetch($stmt);

    echo "name: $result";

    // clean up your mess!
    mysqli_close($stmt);
+1  A: 

you forgot to include your compiled statement in binding results:

mysqli_stmt_bind_result($stmt, $result);

also note, that mysqli_fetch is deprecated, have you tried using a classic fetching while loop?

while (mysqli_stmt_fetch($stmt)) {
    print_r($result);
}
Juraj Blahunka
doesn't seem to do the trick for me i'm afraid. thanks though
Drew
+1  A: 

When using procedural style, you should pass $stmt into mysqli_stmt_bind_param, mysqli_stmt_execute, mysqli_bind_result etc

mysqli_stmt_bind_param($stmt, "s", $region);
mysqli_stmt_execute($stmt);
mysqli_bind_result($stmt, $result);
while (mysqli_stmt_fetch($stmt)) {
    print_r($result);
}
Qwerty
awesome! knew it'd be something i left out! thanks for this. it works a treat now!
Drew