Can anyone help me understand why

Can anyone help me understand why

function getCategoryNameById($id)
{
global $conn;
$sql = "SELECT name FROM categories WHERE id=$id";
$result = mysqli_query($conn, $sql);
$category = mysqli_fetch_assoc($result);
return $category['name'];
}

Is getting this error?

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

Attached: php-logo.png (800x420, 16K)

Other urls found in this thread:

php.net/manual/en/mysqli.query.php
pastebin.com/GvYsS8Uu
pastebin.com/ge0LfAuv
twitter.com/SFWRedditGifs

$result is a bad boy

First of all, your query does not have a terminating semicolon. Not sure if single statement queries go through in php or not. Second, RTFM
php.net/manual/en/mysqli.query.php
mysqli_query returns false if there's no result or an error, and for some queries, simply returns true.
You are the epitome of a php "programmer." You should be ashamed of yourself and should apply for a job as a walmart door greeter

>query does not have a terminating semicolon
why in the fuck do you need terminating semicolon when quering through mysqli_query?

user this is my first time using php. I am not Pajeet.

Noob in need of help.

>using php in 2019
stop
>using 2005 php in 2019
Just kys

Do you even search for jobs, user?
More than 60% of jobs is filled with PHP and JavaScript.

Wonder if your $conn is fucked
put this before your query
if (mysqli_connect_errno())
{
die "Failed to connect to MySQL: " . mysqli_connect_error();
}

>not accessing mysql in oop manner
$conn = new mysqli($hn, $un, $pw, $db)
if($conn->connect_error) die("Fatal Error Faggot");

Js yes, php is rare. Even C# is more common. Stop learning a dead language.