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.

I have that in config.php and included confi.php in my page. Definitely connected to the db. I have another page that displays all published pages, trying to do this page to display posts by category.

>php is rare
nope! Almost any web dev. job requires you to have the knowledge of php and js with at least efficient in one framework of a given language.

Legacy systems only
Have fun maintaining 20 year old shit
Python is where it's at (also js for backend but fuck that shit language)

>also js for backend but fuck that shit language
yes!

Updating wordpress is not a web dev job

yet it was too hard to read the return values. Also procedural and non prepared statements.

Literally kys

But laravel is fucking comfy.

Die in a fire faggot.

sweet sanitized input

>laravel
The whole Facade stuff really makes for bad maintainable code. Symfony is where it's at.

mysql_query was deprecated in php 5.5 (2013) and removed in 7.0 (2015).

He's got a point though. If you can't solve shit like this in one minute by googling or reading the basic, most simple documentation on the matter you're using the wrong language or you're in the wrong field.

True

getCategoryNamebyId("1 UNION ALL SELECT * FROM users");

OP is using the replacement for it, mysqli_query.

>If you can't solve shit like this in one minute by googling or reading the basic, most simple documentation on the matter you're using the wrong language

No other language will solve the problem here. At least he's not writing JS and having functions return Promises and fuck with him.

Attached: ZcZbVeW_Wsv8k7YdshcIOZbCwAHED81Y_QmikGNCpT0.jpg (705x767, 58K)

>"SELECT name FROM categories WHERE id=$id"

Should be
"SELECT name FROM categories WHERE id='$id'"

Fuck off pajeet go tech support somewhere.

Kek, retard

can you try this?

print_r($category);

> Not using pdo

Holy fuck user please don't deploy this anywhere.

this, OP is a faggot

Where does $id come from?
Please escape it appropriately.

Because mysqli_query returns false on error. A poor man's monad of sorts.
Use PDO. That codee you posted is dreadful for many reasons.

just do $sql = $conn->query("SQL")->fetch_assoc();

or use PDO

Tfw when you write a php api in a weekend that is faster and more flexible that the java api that your company has spent 18 months writing.

Don’t forget to prepare your statement, you fucking noob.

Its most likely sanitized before through some other method. JK pajeets wrote it hahahahaha ur fucked

$sql = 'SELECT name FROM categories WHERE id="$id"';

Do not use Mysqli, use PDO with prepared statements and read this phptherightway.com

Ok guys, i'm almost there.

Just got these lat two errors left.

[code}Notice: Undefined variable: posts in /home/ttestdmor/public_html/filtered_posts.php on line 24

Warning: Invalid argument supplied for foreach() in /home/ttestdmor/public_html/filtered_posts.php on line 24[/code]

Pls help me Pajeets.

Attached: 1322089207410.jpg (500x375, 59K)

lmao btfo

What you had wasn’t an array when you ran for each on it.

What do I need to change?

Jow Forums won't let me post the php

pastebin.com/GvYsS8Uu

And for all of you other fags I already told you this is my first time using php so don't give me shit over what is wrong and what is right.

Attached: 1327162846670.jpg (587x532, 58K)

Forgot to paste this

pastebin.com/ge0LfAuv

Which goes above
pastebin.com/GvYsS8Uu

Attached: 1335697479334.png (246x297, 142K)

>global $conn;
Absolutely gross.

HAVING COUNT(1) = 1
what is wrong with you?

>what is wrong with you?
I am a noob using php for the first time. Can you explain what is wrong?

Attached: Doggo.webm (480x208, 406K)

no group clause required there,
get your shit together

Attached: codegeass1001LG.jpg (400x275, 26K)

Well I would if I knew how to, nut I don't. That is why I am here.

Attached: Black People.webm (640x480, 2.37M)

as in many other programming languages, php has a specific rule set written in the documentation.just like Jow Forums, and you know what the rules are in Jow Forums? clearly not.

here is a good rule:
Jow Forums is NOT your personal tech support team or personal consumer review site.

funny aint it? just reading the rules... maybe read the god damn documentation faggot

Wpw thanks, nice to know there are genuine helpfull people still left in this world.

Thanks for your help user.

>phone posting
>sarcastic bitch response
you have to go back.
also, drop php and go with python and use some shitty library that supports cursor objects, it'll be easier for you.
there's still documentation for you to read though which will complicate things because you're an illiterate nigger, but it beats php in this case

>you have to go back
I was always here though