php - Fatal error Invalid parameter number: mixed named and positional parameters -


i'm getting fatal error when try add $stmt->bindparam(':username', $username, pdo::param_str); script. below part of script. i'm trying use session username along id. if take out username = :username , $stmt->bindparam(':username', $username, pdo::param_str); work fine.

fatal error i'm getting:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: mixed named , positional parameters' in /home/www/test.php:7 stack trace: #0 /home/www/test.php(7): pdostatement->execute() #1 {main} thrown in /home/www/test.php on line 7

    $action = isset($_get['action']) ? $_get['action']: ""; if($action=='delete'){ $username    = $_session['user']['username'];<<<<<<<<i add line $query = "delete hostingpackage  username = :username , id = ?";         $stmt = $db->prepare($query);         $stmt->bindparam(1, $_get['id']);         $stmt->bindparam(':username', $username, pdo::param_str);<<<<i add line         $result = $stmt->execute();         header("location: test.php");         die("redirecting test.php");        } 

as error says attempting bind param 1 , :username in 2 statements. guess confusion usage of hash notation , ?.

it's better not mix notations, use either ? throughout or use hash notation :username throughout.

please try:

$query = "delete hostingpackage  username = :username , id = :id"; $stmt->bindparam(':username', $username, pdo::param_str);<<<<i add line $stmt->bindparam(':id', $_get['id']); $result = $stmt->execute(); 

or this:

$query = "delete hostingpackage  username = ? , id = ?"; $stmt->bindparam(1, $username, pdo::param_str);<<<<i add line $stmt->bindparam(2, $_get['id']); $result = $stmt->execute(); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -