NodeJS - Condition Server Side not working. But in PHP it does. Same stucture

In my php setup it picks up the database as “auction_id” as integer…
php-setup-picks-it-up-as-integer

In node… i setup a direct connection to the database on localhost.

But it reads the integers as strings… could that be the issue?
sting-if-integer

If you look at the debug… this is the big diffrence between the code…

if you scoll up all the screenshots are at the top… i wanted to do a “insert” but the THEN/ELSE did not go as planned…

Which conditional setvalue is shown if all three conditions are met?

Can you, in simple English explain - "I want to check if … "

Lets just try again… @Teodor @patrick

NODE JS.

I have a form… that submits to a database.
I have deleted the database connection and reconnected it and pics up the stings as integers now.

When I submit the form it should insert the data into the database because its not in the database.
eg… set the value to insert data to database and basically insert… * set value it just to i can see it in the browser window for testing.

So here is the form… I submit the data…
Then it says it is in the database… clearly its NOT…

So… why is it stopping here … because its not in the database and should have been added?
SO now i turn on the DEBUG to see why.
Then i get on the page… Query [object Object] so this is where its going funny…

So even if the data is NOT in the database it wont submit…

+++++++++++++++++++

Just to show it working… on the same logic…
Now we go to PHP
We setup the same thing… same database… same connection… as i have dont this many other times.

We have the form that submits to the database…

It working as it adding it to the database :slight_smile:
3a

Now i try to add the same record… and it working as expected… checking the condition… the record is there… so it does not insert it… so it working as needed…

Now FOR DEBUGGING… i first delete the “record” so that is not in the database anymore.
because we want to see what PHP outputs so that we can compare the debug outputs.


Perfect… shows the query and all good… so its working as expected…

… no if you compare that same structure… it boms out for me in Node…
check its debug… when it get to the query part… it gets to [object Object]

I am on a localhost … and using a direct database connection…

I dont know how to explain this better…
In a nutshell… the same thing works on PHP in wappler… but gives me a error in Node… but the logic remains the same…

so for some weird reason… for me…
this is where node does not do its thing for me… where php render below…

Obviously your condition is not correct.
Maybe answer my questions above and turn that debug option off and I will be able to help you.
You are going in too different directions and non related topics in your answers, while I expect a simple 3 words answer to:

Debug is off

This is the result

Please see the long message just above your post t… shows the debug is off… and the 2 compared… same thing… just different tech…

What is the condition you want to check? If a database returns a record? The database results count?
What is your database query type?

It’s really not that hard to explain:

I want to check if a database query returns a result

And

My query is a single query

Is that what you are trying to check?

its all in the images…

I have a form… 3 fields…
auction_id
user_id
item_id

that has the value 98 9 4065
I submit this… I then first call a database query… to check this.

so the condition checks… if its true…
if-condition-is-true
Then do nothing…
Else… Insert the record…
inseert

Its a multiple query as im checking all the records…
multi

I really dont know how to exlain this more… i have posted step by step screen shots…

So you want to check if your database query returns any results?

Yes… as its the same as the php… same steps? same logic? in the UI?

Well you could have answered this like 5 replies back.
Try using the count formatter for your condition and check if database query count > than 0

1 Like

Hi Teodor. Doing that, did the magic. Thank you… So my question is… i have 350+ plus api / server actions that used conditions like this… without the .count() > 0 in php working like a charm… But i guess i have to update this now for node… any reason why to logic have changed on this… or is it just a node thing?

A simple search and replace should do the trick i guess… or i hope so… :slight_smile: :slight_smile:

Are you sure that’s the problem? I am not at my computer now but I am mildly sure I don’t use count to evaluate if the query returned results.

I dont know… but it solved it for now… as i dont have strenght anymore… as i need to get this site converted… it was just weird … but anyway… if you want to give it a test… run a localhost wamp for the databse… so own development server and phpmyadmin as I still have loads of php projects im supporting… … but at least this is a solution for now…

update! 350 api / server connect files updated with .count() > 0 … my mouse is dead now… paste… paste… my eyes… … paste… paste… … done… fook me…

1 Like

Just so you are clear on how the database query works with the if condition.
If it is a single record query then you can simply use the query name I.e. check BUT if you are returning a multiple query you must either check the count of records in the query I.e check.count or a value in the first record for example check[0].id > 0
Latter is probably best practice

3 Likes

Hi @Hyperbytes… but this only applicable to Node? or any NEW queries in php?
Because the last time I checked… i still do php conditions like this without [0] or .count() > 0.

See here… and working like a charm php and still working… on 350+ server actions… :slight_smile:
LOL… i did get it from a tutorial back in the day… … mmmm think is might have even been you @Hyperbytes :slight_smile: :slight_smile:

Hence the confusion and frustration… as the same logic did not work for Node… as i presumed it would… but at least its resolved now… as I did not know you should do this… im just glad its working now…

So if you ever convert any php project remember to add this .count() > 0 to any of your (database query) conditions…

like this … i hope this will help somebody else… that is ever going to convert from php… as this was very frustrating… but now solved. At least i did learn something new… … thanks to all that gave a post and replied… much appreciated … as the saying goes… “so you learn”

Just checking a variable name of a query to see if it has records is wrong. It might have worked in PHP because there is no distinction between arrays and objects, but it is just wrong to use because of the too much ambiguity.

So it is better to specifically check what you need if the variable exists or have records with count.

2 Likes

@George would you include a single record query in that. I always understood it returned an empty record if not found so will always evaluate to false?