如何从另一个表/数据库表中复制数据?

时间:2018-05-19 13:43:43

标签: php mysqli

我在发布之前已经阅读了我的所有similer帖子,但无法解决它。 刚从$ mysqli面向对象开始pdo。 我需要从品牌中复制品牌ID并插入产品中,我尝试了几种方法并不断收到错误:

  

致命错误:未捕获PDOException:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

我知道它说我的问题在于参数,但是在4个小时之后就无法解决。

这是我的代码:

    $stmt = $pdo->prepare("INSERT INTO products 
    (userid, catid, item_name, item_desc, item_qtty, item_price, item_seo_url, item_image, item_date, brand) 
    SELECT brand_id FROM brands WHERE user_id = :user_id");

    $stmt->bindParam(':userid', $user_id);
    $stmt->bindParam(':catid', $catid);
    $stmt->bindParam(':item_name', $item_name);
    $stmt->bindParam(':item_desc', $item_desc);
    $stmt->bindParam(':item_qtty', $item_qtty);
    $stmt->bindParam(':item_price', $item_price);
    $stmt->bindParam(':item_seo_url', $item_seo_url);
    $stmt->bindParam(':item_image', $item_image);
    $stmt->bindParam(':item_date', $created_date);
    $stmt->bindParam(':user_id', $user_id);


    $userid = $user_id;
    $catid = $catid;
    $item_name = $item_name;
    $item_desc = $item_desc;
    $item_qtty = $item_qtty;
    $item_price = $item_price;
    $item_seo_url = $item_seo_url;
    $item_image = $item_image;
    $item_date = $created_date;

if($stmt->execute()){
    echo " Records created successfully. Redirect to landing page";
    header("location: index.php");
    exit();
} else{
    echo "Something went wrong. Please try again later.";
}

$pdo = null;

Source

0 个答案:

没有答案