def create_signature(username, password):
def create_signature(username: str, password: str) -> bytes:
Quote style consistency
Pick single or double:
'Authorization' : "Basic "
Connection string security
Please (please) do not store a password as a hard-coded source global:
SERVER = 'localhost'
USER = 'root'
PASSWORD = ''
You calculate these sums:
sum(case when s.type = 'in' then s.quantity else 0 end) as 'in',
sum(case when s.type = 'out' then s.quantity else 0 end) as 'out'
but then reduce them to a 0/1 here:
if(coalesce(x.in - x.out, 0) = 0, 0, 1) as quantity,
This means that a sum is not appropriate at all. This should be refactored to an if exists, ...
Alas, an online search for 'php tutorial' returns plenty of outdated tutorials, some of which are downright dangerous (SQL injections). It's no wonder newcomers to PHP perpetuate bad code and bad practices. This kind of code does not belong in 2020, nowadays developers are expected to use development frameworks and not Notepad or some variant - Example
Please read about sql injection. Basically you should be using prepared statements with parameters for executing SQL queries - either PDO::prepare() or mysqli_prepare(). If that isn't enough of a clue, consider the case where $_POST['body'] contains something like body');DROP TABLE users; or some variant that leads to successful WHERE conditions that end up ...
It looks like your script is part of a basic ajax searching technique.
$_POST is typically used when writing to the database (or when there is a distinct reason that $_GET is unsuitable). Since you are merely SELECTing data, just use $_GET.
if you are going to validate your incoming data, don't bother acquiring resources until after you have validated the ...
In my testing with mysql-connector 2.2.9, bulk insert queries using executemany() were automatically batched as described in the mysql-connector documentation UNLESS they used 'INSERT IGNORE'. (I have yet to test 'ON DUPLICATE KEY …' statements.)
I found that the difference was up to 100x faster for plain 'INSERT' statements vs. 'INSERT IGNORE'; batching is ...
I can't comment, but I have a question for you.
Why don't you use the jeep id of Facebook as a unique key, this way duplicates will not be a problem.
Now for the code review
I saw other responses told you you have bugs in your code, I didn't check your code for bugs. But please follow their advice.
This is my add-on above all that was ...