1

Based on Inserting multiple rows in a single SQL query? page, i have followed the answer on this page to adding multiple rows in sql, but not success.

UPDATE :

I forget to inform the problem : Only first row added success to db. ==> (idkeg, nama, desk, tgl, 71)

How to fix this?

mysqli_query($koneksi, "INSERT INTO keg(idkeg, nama, desk, tgl, kdwil)
                                                        VALUES
                                                        ('$idkeg','$nama', '$desk', '$tgl',71),
                                                        ('$idkeg','$nama', '$desk', '$tgl',72);
                                                        ") or die(mysqli_error());

i am using PMA 3.2.4 & Sql Client 5.1.4.1

How to solve this? Thanks

6
  • Your code is vulnerable to SQL injections. Please learn to use prepared statements. Commented May 14, 2017 at 9:16
  • You missed a closing double quotes. Commented May 14, 2017 at 9:17
  • @frz3993 sorry, i hv upadte my code, Commented May 14, 2017 at 9:18
  • So, any error? Did you check the connection $koneksi is successful or not? And mysqli is for mysql, supposedly won't work with mssql. Commented May 14, 2017 at 9:20
  • @frz3993 sory for my missed, i forget to inform the problem : Only first row added success to db. ==> (idkeg, nama, desk, tgl, 71) How to fix this? Commented May 14, 2017 at 9:28

3 Answers 3

1

Use space between 'keg' and '(' as you using keg( . Rest seems OK accept if you forget to use " for ending. As I'm not seeing it here.

Sign up to request clarification or add additional context in comments.

2 Comments

sory for my missed, i forget to inform the problem : Only first row added success to db. ==> (idkeg, nama, desk, tgl, 71) How to fix this?
Are you using same key value in your idkeg value or any of your unique column. If so then it will only take your first entry.
0

I Hope this helps!

$query = "INSERT INTO keg (idkeg, nama, desk, tgl, kdwil) VALUES('$idkeg','$nama', '$desk', '$tgl',71), ('$idkeg','$nama', '$desk', '$tgl',72)";

$result = mysqli_query($koneksi, $query);
if($result){
   echo "Your data has been inserted";
}
else{
 echo "Data insert Error";
}

Comments

0

Try with this:

if($koneksi->query("INSERT INTO keg (idkeg, nama, desk, tgl, kdwil) 
               VALUES 
                      ('$idkeg','$nama', '$desk', '$tgl',71), 
                      ('$idkeg','$nama', '$desk', '$tgl',72)"
              )                                                             
   ){                                                        
   echo "Multi-INSERT failed: (".$koneksi->errno.")".$koneksi->error;)
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.