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. The Lounge
  3. problem

problem

Scheduled Pinned Locked Moved The Lounge
helpphpdatabase
11 Posts 9 Posters 1 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.
  • D Offline
    D Offline
    diyan pabasara
    wrote on last edited by
    #1

    Parse error: syntax error, unexpected variable "$query" in C:\xampp\htdocs\sys\functions.php on line 10 here is the code -

    $query = "select * from users where user_id = '$id' limit 1";

        $result = mysqli\_query($con,$query);
        if($result && mysqli\_num\_rows($result) > 0)
        {
            $user\_data = mysqli\_fetch\_assoc($result);
            return $user\_data;
        }
    }
    //header('Location: loginsys.php');
    //die;
    

    }

    F OriginalGriffO D 3 Replies Last reply
    0
    • D diyan pabasara

      Parse error: syntax error, unexpected variable "$query" in C:\xampp\htdocs\sys\functions.php on line 10 here is the code -

      $query = "select * from users where user_id = '$id' limit 1";

          $result = mysqli\_query($con,$query);
          if($result && mysqli\_num\_rows($result) > 0)
          {
              $user\_data = mysqli\_fetch\_assoc($result);
              return $user\_data;
          }
      }
      //header('Location: loginsys.php');
      //die;
      

      }

      F Offline
      F Offline
      FranzBe
      wrote on last edited by
      #2

      You should read the posting rules, the top entry in this list. You could read there that this is the wrong place for your question.

      J 1 Reply Last reply
      0
      • D diyan pabasara

        Parse error: syntax error, unexpected variable "$query" in C:\xampp\htdocs\sys\functions.php on line 10 here is the code -

        $query = "select * from users where user_id = '$id' limit 1";

            $result = mysqli\_query($con,$query);
            if($result && mysqli\_num\_rows($result) > 0)
            {
                $user\_data = mysqli\_fetch\_assoc($result);
                return $user\_data;
            }
        }
        //header('Location: loginsys.php');
        //die;
        

        }

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        This forum is the wrong place to post this, as it says at the top of the page. The right place is here: Ask a Question[^] And don't do SQL like that: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause problems because SQL receives commands like:

        SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

        The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

        SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

        Which SQL sees as three separate commands:

        SELECT * FROM MyTable WHERE StreetAddress = 'x';

        A perfectly valid SELECT

        DROP TABLE MyTable;

        A perfectly valid "delete the table" command

        --'

        And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you? But to be honest, the problem you have noticed is pretty trivial to fix: what should a line end with in PHP?

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        G T O 3 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          This forum is the wrong place to post this, as it says at the top of the page. The right place is here: Ask a Question[^] And don't do SQL like that: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause problems because SQL receives commands like:

          SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

          The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

          SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

          Which SQL sees as three separate commands:

          SELECT * FROM MyTable WHERE StreetAddress = 'x';

          A perfectly valid SELECT

          DROP TABLE MyTable;

          A perfectly valid "delete the table" command

          --'

          And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you? But to be honest, the problem you have noticed is pretty trivial to fix: what should a line end with in PHP?

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          G Offline
          G Offline
          g_p_l
          wrote on last edited by
          #4

          https://hackaday.com/2014/04/04/sql-injection-fools-speed-traps-and-clears-your-record/

          L 1 Reply Last reply
          0
          • G g_p_l

            https://hackaday.com/2014/04/04/sql-injection-fools-speed-traps-and-clears-your-record/

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

            You don't wipe an entire database for a fine.

            Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            1 Reply Last reply
            0
            • F FranzBe

              You should read the posting rules, the top entry in this list. You could read there that this is the wrong place for your question.

              J Offline
              J Offline
              jsc42
              wrote on last edited by
              #6

              FranzBe wrote:

              You should read the posting rules, the top entry in this list. You could read there that this is the wrong place for your question.

              ... but there is a right place for a semicolon

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                This forum is the wrong place to post this, as it says at the top of the page. The right place is here: Ask a Question[^] And don't do SQL like that: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause problems because SQL receives commands like:

                SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

                The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

                SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

                Which SQL sees as three separate commands:

                SELECT * FROM MyTable WHERE StreetAddress = 'x';

                A perfectly valid SELECT

                DROP TABLE MyTable;

                A perfectly valid "delete the table" command

                --'

                And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you? But to be honest, the problem you have noticed is pretty trivial to fix: what should a line end with in PHP?

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                T Offline
                T Offline
                trønderen
                wrote on last edited by
                #7

                How is it possible to discuss such matters without a link to Bobby Tables[^]? Sure, it has been referenced in numerous earlier threads. That is because it has been equally relevant to numerous earlier threads. As well as to this one.

                OriginalGriffO 1 Reply Last reply
                0
                • T trønderen

                  How is it possible to discuss such matters without a link to Bobby Tables[^]? Sure, it has been referenced in numerous earlier threads. That is because it has been equally relevant to numerous earlier threads. As well as to this one.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  While XKCD is right, and spot on (and generally Randal is very good at science stuff) it is a cartoon. So those who have never explored the internet other than FarceBook and Twatter - which includes most students - can easily assume that it's a joke. Which it is, but they don't see the levels of reality behind the joke. Omitting Bobby Tables was a deliberate choice to not have the "less experienced" reader disregard it as humour. Since most of 'em don't read past the first sentence of any reply that doesn't start with "here's code you can hand in as your own homework" anyway, it's probably a moot point. But still, we try ... :laugh:

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    This forum is the wrong place to post this, as it says at the top of the page. The right place is here: Ask a Question[^] And don't do SQL like that: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause problems because SQL receives commands like:

                    SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

                    The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

                    SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

                    Which SQL sees as three separate commands:

                    SELECT * FROM MyTable WHERE StreetAddress = 'x';

                    A perfectly valid SELECT

                    DROP TABLE MyTable;

                    A perfectly valid "delete the table" command

                    --'

                    And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you? But to be honest, the problem you have noticed is pretty trivial to fix: what should a line end with in PHP?

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    O Offline
                    O Offline
                    obermd
                    wrote on last edited by
                    #9

                    Obligatory [xkcd: Exploits of a Mom](https://xkcd.com/327/)

                    OriginalGriffO 1 Reply Last reply
                    0
                    • O obermd

                      Obligatory [xkcd: Exploits of a Mom](https://xkcd.com/327/)

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #10

                      Ref: The Lounge[^] And: The Lounge[^]

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      1 Reply Last reply
                      0
                      • D diyan pabasara

                        Parse error: syntax error, unexpected variable "$query" in C:\xampp\htdocs\sys\functions.php on line 10 here is the code -

                        $query = "select * from users where user_id = '$id' limit 1";

                            $result = mysqli\_query($con,$query);
                            if($result && mysqli\_num\_rows($result) > 0)
                            {
                                $user\_data = mysqli\_fetch\_assoc($result);
                                return $user\_data;
                            }
                        }
                        //header('Location: loginsys.php');
                        //die;
                        

                        }

                        D Offline
                        D Offline
                        dandy72
                        wrote on last edited by
                        #11

                        I know nothing about PHP, but aren't you missing a terminating ";" after your $id assignment? (and I won't get into what others have pointed out already, including the posting rules...)

                        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