I’m working on a little form for a non-profit to help them manage some of their information. The form is mostly made up of checkboxes which need to enter “true” into their database column if they are checked or, if they’re not checked enter “false” into their database column. I’m trying to write a little function that I can use to make this distinction for each column I’m entering a variable into. Is there a way for me to use a function inline in SQL to do this? What I’m trying now is this:
That worked! Thank you for the help. Unfortunately, now the SQL insert is turning “true” into a 1 and “false” into a 0 when they’re inserted into the database as values. For this project, my client needs them to say “true” or “false”. Is there a way to keep sql from turning them into numbers?
INSERT INTO boulderreads_tutor_reports
(got_job, got_better_job, improved_on_the_job_skills)
VALUES (true, 'true', 'true')
With no quotes around the first true, so it won’t be treated as a string. Try building your query in a string so you can echo it to debug if you have troubles in future.
Also if some other string like ‘catapult’ is passed into checkValue then that will be returned instead of ‘true’