Retrieving data from the database in php functions

advertisements

I want to fetch data from my database in the function below but it's not working and I don't understand why, can anybody help?

$sql1 = "SELECT * FROM users WHERE uname='Honey' AND pass='Honey'";
$count = mysqli_num_rows( mysqli_query($con, $sql1) );
if ($count > 0 ) {
    $query = mysqli_query($con, $sql1);
    while ($rss = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
        function user_names() {
            $master = .$rss["uname"].;
            $api = "".$master."";
            if (empty($api)) return "Missing";
            $data = "api=".$api."&mask";
            $ch = curl_init();
            curl_close($ch);
            return $content;
        }
    }
}


Let me try to fix your code

$sql1 = "SELECT * FROM users WHERE uname='Honey' AND pass='Honey'";
$query = mysqli_query($con, $sql1) ;
$count = mysqli_num_rows($query);
if ($count > 0 ) {
    while ($rss = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
        user_names($rss);
    }
}

function user_names($rss) {
    $master = .$rss["uname"].;
    $api = "".$master."";
    if (empty($api)){
         return "Missing";
    } else {
        $data = "api=".$api."&mask";
        $ch = curl_init();
        curl_close($ch);
        return $content;
    }
}

I left over some of your not known stuff like $content and also I dont know where you using $data but I assume you have greater code and this is only left overs or something. Maybe you ment to return $data but maybe not. And if you want to put username inside a function you can do like this

user_names($rss);

and in function

function user_names($rss){
    echo $rss['uname'];
}