Data existing check before inserting a record in SQL

Hi,

I would like to validate the data before inserting a record in SQL.

But the data is not a single column data but a combination.

I would like to insert a record if the return of the following SQL doesn’t exist.

SELECT idevent, iduser
FROM votes
WHERE idevent = {{$_POST.idevent}}
AND iduser = {{security1.identity}}

When I wrote this SQL in Database Custom Query, I got SQLSTATE[42000] error.

In this case, how can I set up an action step?

Thanks,

Setup the query, using the query builder and add the conditions there. There is no need to use custom query for this, I suggest avoiding custom queries for all the cases you can use the visual query builder, as when writing custom sql code chances to enter something wrong is really high :slight_smile:

After the query step, add a condition and select the query as an expression.
If the query returns a result the steps in the then part of the condition will run.
If the query doesn’t return a result, the else part will run.

In query builder, is it possible to setup such steps?

I made this though, I have no idea what to do next…
By the way, I wrote insert part in database insert…

I don’t really understand what do you mean/what do you ask about in your last post.
I already explained the steps required:

1 Like

Ok now I found “condition” in action steps.

Thanks!!

I set action steps as you said.
(I set the condition above in query2)

23

but I got 500 error with this message.

Please let me know how to solve this part?

What exactly do you have in the response step? Please post a screenshot.

I think this is a mistake.

by the way, I would like to make an alert popup in this step.

18

How is this step defined exactly? Please post a screenshot!

These are steps.
23

And this is query2 in the steps.

@Miwa
I only need to see the configuration of the RESPONSE STEP.
That’s what I asked you in my last 2 replies…

  1. Select the response step.
  2. Make a screenshot of what is setup there.
  3. Post this screenshot here so I can check it.

35

you mean this?

I keep trying, so this text part was written in “Status” of response properties at the beginning.

Yes of course!
And it’s wrongly setup.
You need to fill the name and status fields. Status is the http error status you want to to return with your server action. Name is the name of your step.
Text is the error message that will be returned.

Thanks! Now it works correctly.
Btw, how can I make this message appear on the screen instead of debug mode…?
I can not set this at dynamic events.

Well, you can show an container/alert based on the server connect status.
You can check the status using the data picker. So, just check for your error status and show the container/alert etc. when the server action status == your status

Sorry again,

31

I set like them, then I get this popup. (I still can see the error text in debug screen)

where did I make a mistake?

Don’t set the status there. Set the error message.

1 Like

Thanks! finally everything works for this server action!

1 Like

It sounds as if you’ve sorted this out now, but an earlier thread discussing might still have some useful information.

1 Like

@TomD thank you so much for useful info! I didn’t know this!!