shams Posted July 21, 2018 Share Posted July 21, 2018 I search the internet to find the solution from multiple row insertion there was many codes but i cannot use for my query this is a piece of code, please help how to execute for multiple rows insertion: <?php $host = 'localhost'; $db = 'test'; $user = 'user'; $pass = ''; $charset = 'utf8mb4'; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass, $options); /////// $cat_id=$_POST['cat-id']; $subcategory=$_POST['subcategory']; $subcat2=$_POST['subcat2']; $subcategory2=$_POST['subcategory2']; $sql = "INSERT INTO subcategory (cat_id, subcategory, subcat2) VALUES (?,?,?),(?,?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$cat_id, $subcategory, $subcat2],[$cat_id, $subcategory2, $subcat2]); ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 21, 2018 Share Posted July 21, 2018 What happens when you run this code? I am curious since I don't think it is written correctly but I want to know what you have tried as far as debugging it. Quote Link to comment Share on other sites More sharing options...
requinix Posted July 21, 2018 Share Posted July 21, 2018 I know the answer but I'll ask anyways: You're calling execute() with two arguments. Two arrays. Why is that? Why do you believe they should be separate? And does the documentation support your belief? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 22, 2018 Share Posted July 22, 2018 Exactly my question.! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.