A cleaner logic would be to just calculate x days from start date. What if you decided to change the trial to 45 days or have multiple trial periods? You would end up writing spaghetti code and doing code gymnastics to get the info you want.
Thatâs actually what you should be doing. You should insert a new row of data into a âsubscriptionâ table to record all the who, what, when, where, and why information about each subscription. The who information would be the userâs id (auto-increment integer primary index in the users table), to relate the subscription record(s) to the user they belong to.
Your database statement error handling is not displaying/logging the reason why a query has failed and since it doesnât stop code execution upon an error, you are getting meaningless follow-on information from your code.
In most cases, a database statement error is a fatal problem, either due to a programming mistake or a database server thatâs not running, and the current web page wonât work. In these cases, thereâs no good reason for your code to continue to run and try to use the result from a query that never executed. If you remove the try/catch logic for these cases and let php catch the database statement exception, php will use its error related settings to control what happens with the actual error information (database statement errors will âautomaticallyâ get displayed/logged the same as php errors) and your code execution will stop and not try to use the result from a failed query. The exception to this rule is when inserting/updating duplicate or out of range user submitted data. In these cases, your code should catch the database statement exception, test if the sql error number is for something that your code is designed to handle, then setup and display a message telling the user what was wrong with the data that they submitted. For all other sql error numbers, just re-thow the exception and let php handle it.
Youâre trying to bind a variable that you donât define anywhere ($trial) to a parameter that isnât in your query (:trial). And why is there a colon before your inner SELECT in the query? I havenât seen that used before.