Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. PHP Fatal error: Uncaught mysqli_sql_exception

PHP Fatal error: Uncaught mysqli_sql_exception

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphpdatabasemysqlsysadmin
10 Posts 2 Posters 154 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aruna KN
    wrote on last edited by
    #1

    I was using a PHP script for a simple message service without any issue upto PHP 7.4, but when I upgrade the PHP version into 8.1, it gives following error_log when trying to send a new message containing "'" eg: I'm ok brother

    PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'm ok brother
    ')' at line 1 in send_message.php:9

    Full code of send_message.php

    Please suggest me a solution

    L 1 Reply Last reply
    0
    • A Aruna KN

      I was using a PHP script for a simple message service without any issue upto PHP 7.4, but when I upgrade the PHP version into 8.1, it gives following error_log when trying to send a new message containing "'" eg: I'm ok brother

      PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'm ok brother
      ')' at line 1 in send_message.php:9

      Full code of send_message.php

      Please suggest me a solution

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Add some code to print out the full statement when it is built. But a far better solution would be to use proper parameterised queries for database access. It has the advantage that you can quickly diagnose issues like this, but more importantly it protects you from SQL injection attacks.

      A 1 Reply Last reply
      0
      • L Lost User

        Add some code to print out the full statement when it is built. But a far better solution would be to use proper parameterised queries for database access. It has the advantage that you can quickly diagnose issues like this, but more importantly it protects you from SQL injection attacks.

        A Offline
        A Offline
        Aruna KN
        wrote on last edited by
        #3

        Actually did you see anything wrong in that code? When trying to store simple text message with ' character (I'm ok brother), it stops processing further and make above mentioned error_log.

        mysqli_query($conn,"INSERT INTO ".C_MYSQL_MESSAGES."(`sender_id`,`receiver_id`,`message`) VALUES (".$_POST['sender_id'].",".$_POST['receiver_id'].",'".$_POST['message']."')");

        I think

        $_POST['message']

        part or near has some issue Can you help me to resolve?

        L 1 Reply Last reply
        0
        • A Aruna KN

          Actually did you see anything wrong in that code? When trying to store simple text message with ' character (I'm ok brother), it stops processing further and make above mentioned error_log.

          mysqli_query($conn,"INSERT INTO ".C_MYSQL_MESSAGES."(`sender_id`,`receiver_id`,`message`) VALUES (".$_POST['sender_id'].",".$_POST['receiver_id'].",'".$_POST['message']."')");

          I think

          $_POST['message']

          part or near has some issue Can you help me to resolve?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Udaya Arunakantha wrote:

          Can you help me to resolve?

          Yes, but you need to do what I suggested above. Whatever is causing the problem can only be discovered by displaying the complete message that MySQL is trying to process.

          A 1 Reply Last reply
          0
          • L Lost User

            Udaya Arunakantha wrote:

            Can you help me to resolve?

            Yes, but you need to do what I suggested above. Whatever is causing the problem can only be discovered by displaying the complete message that MySQL is trying to process.

            A Offline
            A Offline
            Aruna KN
            wrote on last edited by
            #5

            According to your tips, I was able to fix this issue by adding the following code line:

            $_POST['message'] = mysqli_real_escape_string($conn, $_POST['message']);

            L 1 Reply Last reply
            0
            • A Aruna KN

              According to your tips, I was able to fix this issue by adding the following code line:

              $_POST['message'] = mysqli_real_escape_string($conn, $_POST['message']);

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              That may work for now, but your code is still vulnerable to SQL injection attacks. You really should change to using proper parameterized queries for all SQL.

              A 2 Replies Last reply
              0
              • L Lost User

                That may work for now, but your code is still vulnerable to SQL injection attacks. You really should change to using proper parameterized queries for all SQL.

                A Offline
                A Offline
                Aruna KN
                wrote on last edited by
                #7

                Yes I will have to check whole script, this is an old PHP script.

                1 Reply Last reply
                0
                • L Lost User

                  That may work for now, but your code is still vulnerable to SQL injection attacks. You really should change to using proper parameterized queries for all SQL.

                  A Offline
                  A Offline
                  Aruna KN
                  wrote on last edited by
                  #8

                  I decided to remove this post as it's not appropriate to ask huge support for free. Sorry..

                  L 1 Reply Last reply
                  0
                  • A Aruna KN

                    I decided to remove this post as it's not appropriate to ask huge support for free. Sorry..

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Sorry, I do not do private support. If you have a technical issue then post it in the forum. If you want one-to-one consultancy then you need to advertise on freelancer.com or similar.

                    A 1 Reply Last reply
                    0
                    • L Lost User

                      Sorry, I do not do private support. If you have a technical issue then post it in the forum. If you want one-to-one consultancy then you need to advertise on freelancer.com or similar.

                      A Offline
                      A Offline
                      Aruna KN
                      wrote on last edited by
                      #10

                      Sorry Sir..

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups