lawang code

lawang Code


Tanyakan kode disini

MYSQL Echoing Count function in PHP

ditanyakan oleh Vico 4 tahun yang lalu

gan apa yang salah sama code ini, pas ane eksekusi hasilnya selalu

mysql_ fetch_ array always expects parameter 1 to be resource, null given in bla bla

<?php
    include 'config.php';
    $username=$_POST['username'];
        $password=$_POST['password'];
        $email=$_POST['email'];
        $firstname=$_POST['firstname'];
        $lastname=$_POST['lastname'];
        $date=$_POST['date'];
        //create connection with mysql
            $con=mysqli_connect($server,$dbuser,$dbpassword,$databases);
        //check if connection success
            if(mysqli_connect_errno()) {
                echo "Failed to connect mysql : " . mysqli_connect_errno();
            }
        if(empty($username) || empty($password) || empty($email) || empty($firstname) || empty($lastname) || empty($date)) {
            $_SESSION['error']='1';
            header("location:register.php");
        } else {
            $username=stripslashes($username);
            $password=stripslashes($password);
            $email=stripslashes($email);
            $firstname=stripslashes($firstname);
            $lastname=stripslashes($lastname);
            $date=stripslashes($date);
            $username=mysql_real_escape_string($username);
            $password=mysql_real_escape_string($password);
            $email=mysql_real_escape_string($email);
            $firstname=mysql_real_Escape_string($firstname);
            $lastname=mysql_real_escape_string($lastname);
            $date=mysql_real_escape_string($date);
            //$sql = "INSERT INTO users (username,password,email,firstname,lastname,date) VALUES ('$username','$password','$email','$firstname','$lastname','$date')";
            $sql2 = "SELECT COUNT(*) AS total FROM pengguna WHERE username='$username' and email='$email'";
            $result = mysqli_query($sql2);
            $bar = mysqli_fetch_array($result);
            if (mysqli_error())
    {
        echo mysqli_error();
    }
            echo $bar['total'];
            //if(mysqli_query($con,$sql)) {
            //$_SESSION['sukses']='1';
            //}
        }        
        ?>

Menampilkan 1-2 dari 2 hasil
handita okviyanto menjawab 4 tahun yang lalu :

Coba pake yang biasa aja gan..

$query = mysql_query($sql2);
$array = mysql_fetch_array($sql2);

Dan di dump juga biar tahu isinya

var_dump($sql2); 

hasilnya apa coba..


Vico menjawab 4 tahun yang lalu :

sudah sukses dengan ini gan. makasih atas bantuanya ^^

$result = mysql_query("SELECT COUNT(*) FROM user WHERE email='$email' AND username='$username'");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
   echo $row[0] . "\n";
   $total=$row[0];
}


Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 15
X 10

Bantuan

Help

Feedback

Help