Php/SQL Live search bar not working

@Freeranger said:
Parse error: syntax error, unexpected ‘array_unique’ (T_STRING) in /home/vol11_3/epizy.com/epiz_21490173/htdocs/test_update/fetch.php on line 45

If I’m reading between the lines in the official documentation, the statement within the if structure must be on the next line.

So this doesn’t work:

if(mysqli_num_rows($result) > 0) array_unique($data);

But this does:

if(mysqli_num_rows($result) > 0)
    array_unique($data);

This should work as well:

if(mysqli_num_rows($result) > 0) { array_unique($data); }

And, for the sake of completion, this is the only right format dictated by the PSR-2 coding style guide:

if (mysqli_num_rows($result) > 0) {
    array_unique($data);
}

And remember that while Java and PHP are both inspired by C, their syntax is not the same.

Thanks

I just got a big problem - everything stopped working!
Nos, it Will just display all products.

Can you see if you can find whats wrong?
https://pastebin.com/ybhWywW3

Edit: it gives parse error

Parse error: syntax error, unexpected ‘$html’ (T_VARIABLE) in /home/vol11_3/epizy.com/epiz_21490173/htdocs/test_update/fetch.php on line 40

I’ll suggest you to do this
download and install “PhpStorm” 30 days eval.

open new proj. > new PHP file
and paste your code

in the right upper corner you will have red (!)
it will say 2 errors, 6 warnings, 2 typos

or use some other IDE (you mentioned java so you probably have Eclipse or netBeans)
use/run debugger + step by step, etc. every time you have some problem

Thanks!

I figured out there is an unclosed while loop, But when I’m closing it, it says

Parse error: syntax error, unexpected ’ ’ (T_STRING) in /home/vol11_3/epizy.com/epiz_21490173/htdocs/test_update/fetch.php on line 29

Otherwise it says unexpected end of file.

Any idea?

please use phpStorm !

I don’t have access to fetch.php code.

but when I last saw you had an extra } x2

https://pastebin.com/ybhWywW3

as I say use phpStorm and at least check syntax (red || on right when some error + mouseover will show more ~~~~ , etc.)
line 22 and 40 del }

Thanks I Will try it

BTW: Admin, can you see the first version of My first post?

Fixed that error! Can someone go to oilspec.ml/test_update and try to search for one of The products?
Thanks!

Response Fatal error: Uncaught Error: Call to undefined function array_unique() in fetch.php

What does that mean? Sry, I’m not familiar with this error…

paste fetch.php code here for admin
you probably run something before it is declared what this is

pastebin.com/DvhU9ZfL

our admin tries to help even if he stated https://infinityfree.net/support/can-i-contact-support-for-script-help/

so any of you who read this
There is no need to state that you are noobs or green
you have to know that we are all in some way always beginners :slight_smile:

because what you learn today after 5 years is outdated
and to be a programmer you must constantly learning

People think I love computers
no ! computers are just tools for me to express myself

when i learned “java” this version was current

80% I immediately forgot, in the remaining 20%…18% is depricated
and those 2% are something I know

people often ask me
how much do I know about a particular “theme” (java, vb, css, html/xml, db, c ++, php, etc.)

i say 2% :slight_smile:

many think I’m joking !
or how this is a sign of my modesty

but no… !

they do not understand how huge it is!

So if someone tells you he knows 100% or 50% or 20% or 5%
they lie to you !!!

many think to be a programmer is something like a matrix movie
but you actually sit and drink 5+ coffee or energy drinks
watching in the debugger all day (most at night)

it’s so abstract…
it’s a job that someone can work for a maximum of 5 years
and after that you become crazy (just waiting to see the green grass and the sun)

one of the worst things is…
whenever someone asks me (friend or a girl) what I did today ?
I just answer - nothing ! :confused:

because if I start answering them
after 30 sec they are lost (they do not understand what I’m talking about)

Wow

However, this code doesn’t seem to fix the original error:

if (isset($_POST['typehead_search'])) { echo $html; } else { if (mysqli_num_rows($result) > 0) { $data = array_unique($data); echo json_encode($data); } }

Sry for weird formatting, can’t do anything about it really…

how far I see it works

http://oilspec.ml/test_update/

definitely add to your code some limit
how many chars can be entered and how many times per min user can search
otherwise someone will come to you
and do Cat Working GIF - Find & Share on GIPHY

it can be stressful