Related Persons SQL error

Situation
When i try to add a related person i get this error “SQL Statement failed on preparation: SELECT * FROM contact_telecom WHERE contact_id = ? ORDER BY rank ASC, is_primary DESC’“

OpenEMR Version
I’m using OpenEMR version 8.0.0, Mysql

Browser:
I’m using: Firefox

Operating System
I’m using: Ubuntu 24.04

Search
Did you search the forum for similar questions? Yes
The and the columns exist in Mysql

Logs
Did you check the logs?

sudo grep “contact_telecom” /var/log/apache2/error.log

[Fri Mar 06 14:11:16.959309 2026] [php:notice] [pid 10007] [client 192.168.10.34:33626] [2026-03-06T14:11:16.959008+02:00] OpenEMR.ERROR: Error loading relations for display {“foreign_table”:“patient_data”,“foreign_id”:“2601”,“error”:“Failed to execute statement. Error: 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 ‘ASC, is_primary DESC’ at line 1 Statement: SELECT * FROM contact_telecom WHERE contact_id = ? ORDER BY rank ASC, is_primary DESC”} , referer: http://192.168.10.134/openemr/interface/patient_file/summary/demographics_full.php
[Fri Mar 06 14:22:08.668655 2026] [php:notice] [pid 10500] [client 192.168.10.34:38988] [2026-03-06T14:22:08.668532+02:00] OpenEMR.ERROR: Error loading relations for form {“foreign_table”:“patient_data”,“foreign_id”:“2601”,“error”:“Failed to execute statement. Error: 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 ‘ASC, is_primary DESC’ at line 1 Statement: SELECT * FROM contact_telecom WHERE contact_id = ? ORDER BY rank ASC, is_primary DESC”} , referer: http://192.168.10.134/openemr/interface/patient_file/summary/demographics_save.php
[Fri Mar 06 14:22:35.053257 2026] [php:notice] [pid 10129] [client 192.168.10.34:59436] [2026-03-06T14:22:35.053215+02:00] OpenEMR.ERROR: Error loading relations for display {“foreign_table”:“patient_data”,“foreign_id”:“2601”,“error”:“Failed to execute statement. Error: 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 ‘ASC, is_primary DESC’ at line 1 Statement: SELECT * FROM contact_telecom WHERE contact_id = ? ORDER BY rank ASC, is_primary DESC”} , referer: http://192.168.10.134/openemr/interface/patient_file/summary/demographics_full.php
[Fri Mar 06 14:22:44.845034 2026] [php:notice] [pid 10230] [client 192.168.10.34:59462] [2026-03-06T14:22:44.844836+02:00] OpenEMR.ERROR: Error loading relations for form {“foreign_table”:“patient_data”,“foreign_id”:“2601”,“error”:“Failed to execute statement. Error: 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 ‘ASC, is_primary DESC’ at line 1 Statement: SELECT * FROM contact_telecom WHERE contact_id = ? ORDER BY rank ASC, is_primary DESC”} , referer: http://192.168.10.134/openemr/interface/patient_file/summary/demographics_save.php

The finder works nicely - it can search and find existing patients.
Could not replicate in demos. First time i try to use so i do not know if it was working properly before

Thank you

The answer to your question is contained within the question. I hope you were able to solve for the table columns that don’t exist in the native program.

Thank you for answer and time. I am not a programmer so i did not proceed any further. Thankfully is not an essential feature. I may ask an LLM to help me if have i time.
Thank you again

Deep Seek again:)

Here’s the forum summary:


Title: OpenEMR Related Persons Tab — “Error performing search. Network response was not ok: 403” — Solved (Ubuntu 24.04 + Apache + MySQL)

Symptoms:

  • In the patient chart, opening Related Persons and typing in the search fields produced the red error: “Error performing search. Please try again. Network response was not ok: 403”
  • The 403 appeared in the browser’s Network tab on the request to library/ajax/person_search_ajax.php.

Environment:

  • OpenEMR running inside a VirtualBox VM (guest), accessed from Ubuntu 24.04 host via Firefox at http://192.168.10.134/openemr/...
  • Apache2 + MySQL
  • Default install path: /var/www/html/openemr

What we ruled out:

  • Not an OpenEMR ACL problem. The logged-in user was already a member of Administrators, Clinicians, Physicians, Front Office, and Accounting — full permissions. OpenEMR’s ACL layer was not the cause.
  • Not a database problem. The users and gacl_groups_aro_map tables were fully populated and correct.
  • Not a missing Apache module. mod_rewrite and mod_headers were already enabled from a previous fix (see note below).

Root cause:
The 403 was coming from Apache itself, before the request ever reached PHP. The endpoint person_search_ajax.php lives in /var/www/html/openemr/library/ajax/. Apache’s default deny rule applies to any directory that does not have an explicit Require all granted directive, so requests to that path were rejected with 403 before OpenEMR’s PHP code could run.

The prior insurance-form fix had added a <Directory> block for /var/www/html/openemr/apis but not for /var/www/html/openemr/library/ajax.

Fix:

Edit the Apache site config:

sudo nano /etc/apache2/sites-available/000-default.conf

Add before </VirtualHost>:

<Directory /var/www/html/openemr/library/ajax>
    AllowOverride all
    Require all granted
</Directory>

Then clear the Smarty cache and restart Apache:

sudo rm -rf /var/www/html/openemr/sites/default/documents/smarty/main/*
sudo systemctl restart apache2

Result:

  • The 403 disappeared. Search now returns results for surname correctly.
  • Search by first name was still returning nothing at the time of writing — this may be a separate issue with how the query matches first names, and is being investigated separately.

Note — related fix from the same session (insurance edit form):

Earlier in the same OpenEMR install, the insurance edit form was failing to load and save with similar symptoms. Two separate fixes were needed:

  1. Add the same Apache <Directory> block for /var/www/html/openemr/apis and enable mod_rewrite.
  2. Populate the policy_type list in the list_options table:
sudo mysql -e "USE openemr; INSERT IGNORE INTO list_options (list_id, option_id, title, seq, is_default, activity) VALUES ('policy_type', 'primary', 'Primary', 1, 1, 1), ('policy_type', 'secondary', 'Secondary', 2, 0, 1), ('policy_type', 'tertiary', 'Tertiary', 3, 0, 1);"
  1. After those fixes, the save still failed until the patient’s Social Security Number was set in Demographics. Assigning an SSN resolved it.

Key takeaway for anyone hitting 403 errors in OpenEMR:

A 403 on an AJAX endpoint in OpenEMR is almost always Apache, not OpenEMR’s ACL system — especially on a fresh Ubuntu 24.04 install where the default Apache config only grants access to /var/www/html if an explicit <Directory> block is present. If an OpenEMR subdirectory is missing its own Require all granted block, Apache denies access before PHP runs. Adding one block per affected subdirectory (apis, library/ajax, and any others you use) fixes it.

Credits: Diagnosed with help from DeepSeek (deepseek.com).


If the first-name search still fails after your testing, start a new thread here or come back and we’ll dig into person_search_ajax.php — that one may be a query-matching issue rather than a permissions issue.