novumorganon Posted January 26, 2022 Share Posted January 26, 2022 So I have a site for dealing with proprietary issues for my business. Coded it years ago as a website, due to folks working for me from home. Now my servers are forced into the new PHP update, 7.4 I think, and I'm getting this rather vague error: Fatal error: Error executing query: SELECT ca.customer_id, aa.needs_checking, c.agent_id FROM customer_accounts ca, allowed_accounts aa, customers c WHERE aa.allowed_acct_id = ca.account_type AND c.customer_id = ca.customer_id AND ca.is_active =1 AND ca.mail_interval !=0 AND ca.next_check < UNIX_TIMESTAMP() AND aa.needs_checking=1 AND c.word_balance > 150 AND c.agent_id= - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 in /home/customer/www/i-scribes.com/public_html/mysqldb.class.php on line 270 For this line of code: $sql = "SELECT ca.customer_id, aa.needs_checking, c.agent_id FROM customer_accounts ca, allowed_accounts aa, customers c WHERE aa.allowed_acct_id = ca.account_type " . "AND c.customer_id = ca.customer_id AND ca.is_active =1 AND ca.mail_interval !=0 AND ca.next_check < UNIX_TIMESTAMP() AND aa.needs_checking=1 AND c.word_balance > 150 AND " . "c.agent_id={$_SESSION['staff_id']}"; $db->executeQuery($sql); If anyone can help, it would be most appreciated! <3 Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/ Share on other sites More sharing options...
Barand Posted January 26, 2022 Share Posted January 26, 2022 What do you see if you echo $sql; Is there a value at the end where the staff id should be? Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593631 Share on other sites More sharing options...
mac_gyver Posted January 26, 2022 Share Posted January 26, 2022 the error is because the session variable doesn't contain a value. so, two things - code should ALWAYS validate inputs before using them. if a required input isn't valid, that's an error and the code should setup and display a message for the user telling them what is wrong and not attempt to use the input. you need to determine why the session variable doesn't contain an expected value. either it's not being set or it is being lost somewhere along the way. based on the name of that variable, this either has something to do with the user authentication/login system or a user permission system. do other things requiring user authentication/permissions work? there should be other php errors that will help pin point where the problem is starting at. is php's error_reporting set to E_ALL? beyond that, it would take having the code where that session variable is being set at through to the posted code in order to come up with specific things to look at. Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593633 Share on other sites More sharing options...
novumorganon Posted January 26, 2022 Author Share Posted January 26, 2022 3 minutes ago, mac_gyver said: the error is because the session variable doesn't contain a value. so, two things - code should ALWAYS validate inputs before using them. if a required input isn't valid, that's an error and the code should setup and display a message for the user telling them what is wrong and not attempt to use the input. you need to determine why the session variable doesn't contain an expected value. either it's not being set or it is being lost somewhere along the way. based on the name of that variable, this either has something to do with the user authentication/login system or a user permission system. do other things requiring user authentication/permissions work? there should be other php errors that will help pin point where the problem is starting at. is php's error_reporting set to E_ALL? beyond that, it would take having the code where that session variable is being set at through to the posted code in order to come up with specific things to look at. So I think you are right with there being something wrong with sessions. I'm guessing PHP 7 had some updates to how sessions work too? Le sigh, this may not be as easy as I thought. Lol. Thank you for the fast help everyone! Appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593635 Share on other sites More sharing options...
ginerjm Posted January 26, 2022 Share Posted January 26, 2022 Why don't you do an echo of that session var before the query executes and see what it is? Are you sure that you did a session_start at the start of your script (good habit)? Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593636 Share on other sites More sharing options...
mac_gyver Posted January 26, 2022 Share Posted January 26, 2022 4 minutes ago, novumorganon said: I'm guessing PHP 7 had some updates to how sessions work too? no. the most likely thing is php's output_buffering setting being previously ON, but now it is off, preventing things like the session_start() from working, combined with bad code not doing things like halting php execution following header redirects. there would be php errors. Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593637 Share on other sites More sharing options...
novumorganon Posted January 26, 2022 Author Share Posted January 26, 2022 I think it was legit, one part of my Ajax script having a space before session_start(); ... seemed to fix everything for the most part. Very odd. Haha. Thanks again everyone. Quote Link to comment https://forums.phpfreaks.com/topic/314465-php-update-giving-me-mysql-errors/#findComment-1593642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.