Fatal error: Uncaught Error: Call to undefined function query()

Permisi, ini saya error kaya gini terus bingung mau apalagi yang diganti mohon pencerahannya..

Error : Fatal error: Uncaught Error: Call to undefined function query() in C:\xampp\htdocs\web-perpustakaan\config\functions.php:46 Stack trace: #0 C:\xampp\htdocs\web-perpustakaan\register.php(6): register(Array) #1 {main} thrown in C:\xampp\htdocs\web-perpustakaan\config\functions.php on line 46

ini Functions.php <?php

require_once 'koneksi.php';

function upload() {

    $namaFoto = $_FILES['foto']['name'];

    $ukuranFoto = $_FILES['foto']['size'];

    $error = $_FILES['foto']['error'];

    $tmpFoto = $_FILES['foto']['tmp_name'];

    if($error === 4) {

        echo "<script>alert('pilih gambar terlebih dahulu.');</script>";

        return false;

    }

    $fotoValid = ['jpg','jpeg','png'];

    $ektensiFoto = explode('.', $namaFoto);

    $ektensiFoto = strtolower(end($ektensiFoto));

    if(!in_array($ektensiFoto, $fotoValid)) {

        echo "<script>alert('yang anda upload bukan gambar.');</script>";

        return false;

    }

    // cek ukuran

    if($ukuranFoto > 1000000) {

        echo "<script>alert('ukuran gambar terlalu besar.');</script>";

        return false;

    }

    $fileNameBaru = uniqid();

    $fileNameBaru .= '.';

    $fileNameBaru .= $ektensiFoto;

    move_uploaded_file($tmpFoto, '../img/' . $fileNameBaru);

    return $fileNameBaru;

}

function register($data) {

    global $conn;

    $nama = htmlspecialchars($data['nama']);

    $username = $conn->real_escape_string($_POST['username']);

    $password = $conn->real_escape_string($_POST['password']);

    $password2 = $conn->real_escape_string($_POST['password2']);

    // jika username sudah terdaftar

    if(query("SELECT * FROM user WHERE username = '$username'")) {

        echo "<script>alert('Username sudah terdaftar!');window.location='register.php';</script>";

        return false;

    }

    if($password != $password2) {

        echo "<script>alert('konfirmasi password salah.');</script>";

        return false;

    }

    if(strlen($username) < 6 ) {

        echo "<script>alert('Password terlalu pendek, maksimal 6 digit');window.location='register.php';</script>";

        return false;

    }

    // cek gambar

    $foto = upload();

    if(!$foto) {

        return false;

    }

    $password = password_hash($password, PASSWORD_DEFAULT);

    $conn->query("INSERT INTO tb_user VALUES (null, '$username', '$password', '$nama', '$foto')") or die(mysqli_error($conn));

    return $conn->affected_rows;

}

avatar mohammadyudhafergiansyah
@mohammadyudhafergiansyah

2 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Tanggapan

rapikan kode kamu, taro di tag kode agar mudah dibaca, orang malas baca kode yang asal dicopypaste

ampun, baca kodenya gmna itu -_-

1 Jawaban:

<div>Function.php<br><br>&lt;?php&nbsp;</div><div>require_once 'koneksi.php';</div><div><br></div><div>function upload() {</div><div>&nbsp; &nbsp; $namaFoto = $_FILES['foto']['name'];</div><div>&nbsp; &nbsp; $ukuranFoto = $_FILES['foto']['size'];</div><div>&nbsp; &nbsp; $error = $_FILES['foto']['error'];</div><div>&nbsp; &nbsp; $tmpFoto = $_FILES['foto']['tmp_name'];</div><div><br></div><div>&nbsp; &nbsp; if($error === 4) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('pilih gambar terlebih dahulu.');&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; $fotoValid = ['jpg','jpeg','png'];</div><div>&nbsp; &nbsp; $ektensiFoto = explode('.', $namaFoto);</div><div>&nbsp; &nbsp; $ektensiFoto = strtolower(end($ektensiFoto));</div><div><br></div><div>&nbsp; &nbsp; if(!in_array($ektensiFoto, $fotoValid)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('yang anda upload bukan gambar.');&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; // cek ukuran</div><div>&nbsp; &nbsp; if($ukuranFoto &gt; 1000000) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('ukuran gambar terlalu besar.');&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; $fileNameBaru = uniqid();</div><div>&nbsp; &nbsp; $fileNameBaru .= '.';</div><div>&nbsp; &nbsp; $fileNameBaru .= $ektensiFoto;</div><div><br></div><div>&nbsp; &nbsp; move_uploaded_file($tmpFoto, '../img/' . $fileNameBaru);</div><div>&nbsp; &nbsp; return $fileNameBaru;</div><div>}</div><div><br></div><div>function register($data) {</div><div>&nbsp; &nbsp; global $conn;</div><div>&nbsp; &nbsp; $nama = htmlspecialchars($data['nama']);</div><div>&nbsp; &nbsp; $username = $conn-&gt;real_escape_string($_POST['username']);</div><div>&nbsp; &nbsp; $password = $conn-&gt;real_escape_string($_POST['password']);</div><div>&nbsp; &nbsp; $password2 = $conn-&gt;real_escape_string($_POST['password2']);</div><div><br></div><div>&nbsp; &nbsp; // jika username sudah terdaftar</div><div>&nbsp; &nbsp; if(query("SELECT * FROM user WHERE username = '$username'")) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('Username sudah terdaftar!');window.location='register.php';&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; if($password != $password2) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('konfirmasi password salah.');&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; if(strlen($username) &lt; 6 ) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;script&gt;alert('Password terlalu pendek, maksimal 6 digit');window.location='register.php';&lt;/script&gt;";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; // cek gambar</div><div>&nbsp; &nbsp; $foto = upload();</div><div>&nbsp; &nbsp; if(!$foto) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; $password = password_hash($password, PASSWORD_DEFAULT);</div><div><br></div><div>&nbsp; &nbsp; $conn-&gt;query("INSERT INTO tb_user VALUES (null, '$username', '$password', '$nama', '$foto')") or die(mysqli_error($conn));</div><div>&nbsp; &nbsp; return $conn-&gt;affected_rows;</div><div>}</div><div><br><br></div>

avatar mohammadyudhafergiansyah
@mohammadyudhafergiansyah

2 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban