dongzi0850 2012-10-20 17:26
浏览 43

bind_param()中变量的问题

I have error_reporting all the way on and I've looked over it many times, so I think I might be calling a value wrong or didn't declare something correct. Anyone who can jump in and tell me whats up with the code and why still the error " Call to a member function bind_param() on a non-object" because I'm stumped:

$db=new mySQLi($host,$dbhuser,$dbhpwd,$dbh); 
$insert_stmt = $db->stmt_init();    
$insert_stmt = $db->prepare("INSERT INTO food (id,timestamp,userid,tagline,group,location,event_date,event_time,image,type) VALUES(NULL,NOW(),?,?,?,?,?,?,?,?)");
        $insert_stmt->bind_param("issssssi",$_SESSION['id'],$tagline,$organizer,$location,$event_date,$event_time,$image_name,$food_id);
        $insert_stmt->execute();

userid is an integer that I pull from a stored cookie.

$tagline, $organizer, $location, are text with max at 140 chars.

$event_date = $event_date= substr(date('Y'),0,2).$year."-".$month."-".$day; $event_time= date("H:i:s", strtotime($hour.":".$minute.$period)); - all these variable were users input as two digit numbers as text

$image_name is text, a file path

and type is an integer from 1-29.

Here is an example result of the ? values for the database: 38, test, test, test, 2013-2-20, 14:15:00, Halloween_Beer_2.jpg, 7

Here is a screen shot of the setup in mysql for the table called food: enter image description here

  • 写回答

1条回答 默认 最新

  • dotxxh0998 2012-10-20 17:31
    关注
    $insert_stmt = $db->prepare("INSERT INTO food (id,timestamp,userid,tagline,group,location,event_date,event_time,image,type) VALUES(NULL,NOW(),?,?,?,?,?,?,?,?)");
            $insert_stmt->bind_param("issssssi",$_SESSION['id'],$tagline,$organizer,$location,$event_date,$event_time,$image_name,$food_id);
            $insert_stmt->execute();
    

    you are doing wrong.BindParam accepts only a single value

    $query->bindParam("value",":value",PDO::PARAM_INT);// type
    

    you can do something like this

       $insert_stmt = $db->prepare("INSERT INTO food (id,timestamp,userid,tagline,group,location,event_date,event_time,image,type) VALUES(NULL,NOW(),?,?,?,?,?,?,?,?)");
    
    $insert_stmt->execute(array("issssssi",$_SESSION['id'],$tagline,$organizer,$location,$event_date,$event_time,$image_name,$food_id))
    

    Or you can see this PDO tutorial

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探