-3

This has been frustrating me for more than an hour, any help would be appreciated.

I have "marked" the offending code with a comment below

        $hostt = "localhost";
$db_database = "dekit_ryan";
$db_username = "dekit_ry";
$db_password= "s%g0oM";


$link = mysqli_connect($hostt , $db_username, $db_password, $db_database);

if (!$link) {
    printf("Unable to connect to DB, the error is: %s\n", mysqli_connect_error());
    exit();
}


// ************* Problem seems to be with the below line ***********
   $stmt = mysqli_prepare($link, "INSERT INTO campaign(cname,public_ref_name,redirect_to) VALUES (?, ?,  ?)");

        mysqli_stmt_bind_param($cname, $pub_ref_name, $url);
        mysqli_stmt_execute($stmt);

        // Check if the row was successfully inserted or spit out an error
        if(mysqli_stmt_affected_rows($stmt) != 1)
        {
            return "Error: Problem inserting a record into the database, exiting..." . mysqli_errno($link);
            exit;
        }

When I run the script I always get:

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, string given in /home/dekit3/public_html/adTracking/classes/AdsTracking.php on line 44

Error: Problem inserting a record into the database, exiting...0

var dump

object(mysqli)#2 (18) { ["affected_rows"]=> int(0) ["client_info"]=> string(6) "5.1.62" ["client_version"]=> int(50162) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(10) "5.1.62-cll" ["server_version"]=> int(50162) ["stat"]=> string(151) "Uptime: 1210463 Threads: 10 Questions: 45999394 Slow queries: 1585 Opens: 3541810 Flush tables: 57 Open tables: 256 Queries per second avg: 38.1" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(1861790) ["warning_count"]=> int(0) } 
4

2 回答 2

3

The line

 mysqli_stmt_bind_param($cname, $pub_ref_name, $url);

requires that you use as the first parameter $stmt variable.

EDIT

Please take a look at the Example 2 in the manual.

于 2013-06-04T12:30:03.793 回答
3

You are setting incorrect parameters for mysqli_stmt_bind_param. It should be:

mysqli_stmt_bind_param($stmt, 'sss', $cname, $pub_ref_name, $url);

Change 'sss' according the datatypes you have in the database.

Look here:

http://www.php.net/manual/en/mysqli-stmt.bind-param.php

于 2013-06-04T12:31:33.120 回答