Gagal register Fatal error: Uncaught ArgumentCountError

Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at least 2 arguments, 1 given in A:\Program Files\XAMPP\htdocs\pengaduan_masyarakat\add_masyarakat.php:11 Stack trace: #0 A:\Program Files\XAMPP\htdocs\pengaduan_masyarakat\add_masyarakat.php(11): mysqli_query('SELECT * from m...') #1 {main} thrown in A:\Program Files\XAMPP\htdocs\pengaduan_masyarakat\add_masyarakat.php on line 11

Error pas mau buat akun masyarakat, isi PHP dibuat agar masyarakat bisa membuat akun dan mencegah membuat akun dari NIK dan Username yang sama.

add_masyarakat.php
<?php

	include "connection.php";

	$nik = $_POST['nik'];
	$nama = $_POST['nama'];
	$username = $_POST['username'];
	$password = $_POST['password'];
	$telp = $_POST['telp'];

    $cek_masyarakat    =mysqli_num_rows (mysqli_query("SELECT * from masyarakat WHERE username = '$username' AND username = '$password'"));
    if ($cek_masyarakat > 0) {
        echo '<script language="javascript">
              alert ("NIK dan Password telah dipakai");
              window.location="";
              </script>';
        exit();
    }
    else{
		mysqli_query($connect, "INSERT INTO masyarakat VALUES('$nik', '$nama' ,'$username', '$password', '$telp')");
	}


 ?>

connection.php

<?php

$host = "localhost";
$user = "root";
$password = "";
$database = "admas";
$connect = mysqli_connect($host, $user, $password, $database);
 
 if ($connect) {
 //	echo "berhasil koneksi";
 }
 else
 {
 //	echo "gagal koneksi";
 }
?>
avatar user02936

@user02936

12 Kontribusi 4 Poin


Jawaban Terpilih

Baris kode ini :
$cek_masyarakat    =mysqli_num_rows (mysqli_query("SELECT * from masyarakat WHERE username = '$username' AND username = '$password'"));

Di ubah menjadi :
$cek_masyarakat    =mysqli_num_rows (mysqli_query($connect, "SELECT * from masyarakat WHERE username = '$username' AND username = '$password'"));

Semoga berhasil.
avatar ahanafi

@ahanafi

689 Kontribusi 435 Poin

Jawaban

Baris kode ini :
$cek_masyarakat    =mysqli_num_rows (mysqli_query("SELECT * from masyarakat WHERE username = '$username' AND username = '$password'"));

Di ubah menjadi :
$cek_masyarakat    =mysqli_num_rows (mysqli_query($connect, "SELECT * from masyarakat WHERE username = '$username' AND username = '$password'"));

Semoga berhasil.
avatar ahanafi

@ahanafi

689 Kontribusi 435 Poin


sip udah bisa berjalan, makasih gan.
avatar user02936

@user02936

12 Kontribusi 4 Poin


ini maaf mau nanya, bahasa yang dipake java script ya ?

avatar masmashalu

@masmashalu

1 Kontribusi 0 Poin


Login untuk gabung berdiskusi
premium logo tube

Hey, sedang ada diskon premium untuk akses semua kelas. Lihat di sini