如何在select子查询和where子句中使用insert查询?

I am using this but its went wrong

$sql="INSERT INTO `shopping_cart`  
(userid`,`product_id`,`pr_name`, `pr_price`)  
VALUES('$us_id','$pr_id','$pname','$prprice')  
WHERE(SELECT `product_id` FROM `product_tb_men`  
JOIN `shopping_cart` ON product_tb_men.pr_id= shopping_cart.product_id  
WHERE product_tb_men.pr_id=$pr_id)";

May be You need this :

UPDATE `shopping_cart` 
SET userid = '$us_id',
  `product_id` = '$pr_id',
  `pr_name` = '$pname', 
  `pr_price` = '$prprice'
WHERE <field_name_for_id> IN (SELECT `product_id` FROM `product_tb_men`  
 JOIN `shopping_cart` ON product_tb_men.pr_id= shopping_cart.product_id  
 WHERE product_tb_men.pr_id='$pr_id')

WHERE clause cannot used with INSERT. The subquery below of SELECT i have kept as it is what u have given. The changes is in the remaining main query

UPDATE `shopping_cart` 
    SET `userid` = '$us_id', 
      `product_id` = '$pr_id', 
      `pr_name` = '$pname', 
      `pr_price` = '$prprice'
    WHERE `product_id` in (SELECT `product_id` FROM `product_tb_men`  
     JOIN `shopping_cart` ON product_tb_men.pr_id= shopping_cart.product_id  
     WHERE product_tb_men.pr_id=$pr_id);

Try this query:

"INSERT INTO `shopping_cart` (`userid`,`product_id`,`pr_name`, `pr_price`)  
SELECT '$us_id', '$pr_id','$pname','$prprice' FROM `product_tb_men` 
JOIN `shopping_cart` ON product_tb_men.pr_id= shopping_cart.product_id  
WHERE product_tb_men.pr_id= $pr_id"