-8

i got error like this :

Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in

anyone can help me?

i got code like this :

     <?php
        include('rf_koneksi.php');
        $result = mysqli_query($rf_koneksi, "SELECT * FROM pemesanan");
        $htngdata = mysqli_num_rows($rf_koneksi,$result);
        if (isset($_POST['pesan'])) {
            $tanggal_pesan = date('Y-m-d');        
            $jumlah = $_POST['jumlah'];
            $kode_barang = $_POST['rf_kode_baju'];
            $rf_email = $_POST['email'];

            for($i=0;$i<$htngdata;$i++){
                $jml = $jumlah[$i];
                if($jumlah[$i] >0){
                    $id_barang = $kode[$i];
                    mysqli_query($rf_koneksi, "INSERT INTO pesanan(rf_kode_baju, rf_tanggal_pemesanan, rf_jumlah_pemesanan, rf_email_pemesanan) VALUES('$kode_barang','$tanggal_pesan','$jumlah','$rf_email') ");
                }
            }

            }else{  //jika tidak terdeteksi tombol tambah di klik
                //redirect atau dikembalikan ke halaman tambah
                echo '<script>window.history.back()</script>';
            }

        ?>
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Firm
  • 61
  • 2
  • 9
  • Well it is telling you, you are supplying too many arguments (parameters) for the mysqli_num_rows() function, so how about removing one. That is not rocketscience is it? – RST May 23 '17 at 08:26
  • too lazy to even bother checking google or the manual http://php.net/manual/en/mysqli-result.num-rows.php – Kevin May 23 '17 at 08:39

2 Answers2

1

As the error states, that function expects one parameter. You gave it two:

mysqli_num_rows($rf_koneksi,$result)

Instead, give it just the one it's looking for:

mysqli_num_rows($result)

Note: Also be aware that your code is wide open to SQL injection. When you write code in this way, you allow users to arbitrarily execute any code they want on your database. This could be problematic, even downright malicious. Instead of allowing user input to govern your database queries, use prepared statements and SQL parameters. Basically, treat user input as values instead of code. This is a good place to start on the subject: How can I prevent SQL injection in PHP?

David
  • 208,112
  • 36
  • 198
  • 279
  • i got error like this Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in – Firm May 23 '17 at 08:29
  • @Firm: Yes, that was what you asked in the question above. And what this answer corrects. Did you read the answer? Did you try it in your code? – David May 23 '17 at 08:32
  • yeah, i try the code of you and its a same error – Firm May 23 '17 at 08:46
  • @Firm: Then you've made a mistake somewhere. Perhaps you're using `mysqli_num_rows()` in more than one place and need to correct the others as well? – David May 23 '17 at 08:47
0

mysqli_num_rows takes only one parameter a mysqli_result, so you need to remove the connection $rf_koneksi from your call.

change:

$htngdata = mysqli_num_rows($rf_koneksi,$result);

to:

$htngdata = mysqli_num_rows($result);

see http://php.net/manual/en/mysqli-result.num-rows.php for syntax and examples.

Chana T
  • 26
  • 2
  • 3