-2

I am using a logbook to track all user interaction. When trying to save the search of an page to my MySQL database I get this error: You have an error in your SQL syntax; is MySQL seeing this as extra columns now?

$sql_lgb = "INSERT INTO logboek
                (
                    omschrijving,
                    zoek,
                    sort,
                    soort,
                    user_id
                )
                VALUES
                (
                    '".$omschrijving."',
                    '".$zoek_opdr."',
                    '".$sort_name."',
                    'pagina bezocht',
                    '".$_SESSION['user_id']."'
                )
            ";

// resultaat van query
if(!$res_lgb = mysqli_query($mysqli, $sql_lgb)) { include('includes/error_database.php'); die; }

This is the output of the query:

INSERT INTO logboek ( omschrijving, zoek, sort, soort, user_id ) VALUES ( 'Pagina Manuals bezocht', ' (bedrijf LIKE 'torza' OR bedrijf LIKE 'thure' OR bedrijf LIKE 'mb' ) AND (naam LIKE '%%') ', 'naam', 'pagina bezocht', '1' )
Muiter
  • 1,470
  • 6
  • 26
  • 39

1 Answers1

0

The values you are sending to the database has multiple quotations ' in "zoek" value.

To avoid such errors you need to escape them \'.

Or even better use PDO with prepared statements.

ino
  • 2,345
  • 1
  • 15
  • 27