We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    $checkUsername = $modx->db->query("SELECT `id` FROM ".$web_users." WHERE `username`=’".$username."’");
    $limit = $modx->recordCount($checkUsername);

    if ($limit > 0)
    {
    return $this->FormatMessage($this->LanguageArray[7]);
    }

    In my WLPE install, this line of code is giving me an error (right now, there is no users in the web_user table, since I had to empty the table to get rid of a username that was making it act up. BTW, this is from the webloginpe.class.php file.

    Anyways, that line of code returns an error that the user already exists --- could someone explain to me how the PHP works, so I can try to debug the issue? (Oddly enough, this issue does the same thing when it checks the email records, which had basically the same syntax --- and when I remove those two pieces of checking, it gives this error --- might help show what the error is...)

    « MODx Parse Error »MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - Duplicate entry ’Wilhelm’ for key 2 »
    SQL: INSERT INTO `symphon_cms`.`modx_web_users` (`username`, `password`, `cachepwd`) VALUES (’Wilhelm’, ’XXX’, ’XXX’)
    [Copy SQL to ClipBoard]

    Parser timing
    MySQL: 0.0168 s (18 Requests)
    PHP: 0.5884 s
    Total: 0.6052 s

    BTW, I posted this here, since it seems to be a PHP syntax issue, and Scotty’s MIA from that section recently. I thought I might get some help if I posted in a general place like this.
      My Snippets
      -> PopUpChunk v1.0
      • 5811
      • 1,717 Posts
      Hi Soshite,

      As I understand, this lines of codes check if a user already exists or not if the database.
      $checkUsername = $modx->db->query("SELECT `id` FROM ".$web_users." WHERE `username`='".$username."'");
      give you a datarecord set. And
      $limit = $modx->recordCount($checkUsername);
      give you the number of records with username = $username. If the number is upper than 0 that’s means that the user is already registrated and then display the message langageArray[7].
      When you remove these lines and a record already exists with the same username you get a mysql error like duplicate entry for key 2.

      Which is the php error message when you use
      $checkUsername = $modx->db->query("SELECT `id` FROM ".$web_users." WHERE `username`='".$username."'");
      ? Are you sure of the variables $web_users and $username ?
        • 3749
        • 24,544 Posts
        @Soshite,

        Have you browsed the modx_web_users table in PhpMyAdmin to see that it’s there and truly empty. I can’t see how you’d be getting a recordCount > 0 on any query on an empty table.

        If you go into PhpMyAdmin, select that database, select the modx_web_users table, and click on the "browse" tab, you should see a list of users showing the id, username, and password hash.

        BTW, the error you’re getting when you comment out that test is telling you that there is already a Wilhelm in column (field) 2 of the database records and it’s set up so that duplicates in that field aren’t allowed so it refuses to insert the new one. This also suggest that the table is not really empty. Maybe you emptied the wrong table or the right table in another database?

        That field is the "username" field, so you can see why it won’t allow duplicates.

        Bob
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 28033
          • 925 Posts
          There’s an attached image of the modx_web_users table. As you can see, it’s empty. I’ve emptied it out each time I’ve tried to test things out to fix this issue.

          Like if I created an account called lolfakeuser (which obviously doesn’t exist), it says it exists, but oddly enough creates a record in the table, but w/out applying the usergroup setting for the created user. Which is odd, because it should stop everything once it encounters an error, you know?

          And I’ve searched the entire database for Wilhelm (my name before I wiped the table, and the one I’ve been testing w/), and it’s nowhere to be found...I’m really at a loss as to why WLPE’s giving this error. It’s odd, because all the checks before then quit the account creation process as expected before data gets to the database, but for those two, it’s not catching it.
            My Snippets
            -> PopUpChunk v1.0
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            No, it’s not empty. If it were empty, the Browse tab would be greyed out. Also it shows "overhead" as well as data of 80 bytes. Try cleaning that up; perhaps there’s an orphaned or corrupted record or two in there.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 28033
              • 925 Posts
              Quote from: sottwell at Feb 11, 2008, 07:23 AM

              No, it’s not empty. If it were empty, the Browse tab would be greyed out. Also it shows "overhead" as well as data of 80 bytes. Try cleaning that up; perhaps there’s an orphaned or corrupted record or two in there.

              So Empty doesn’t "clean" the table, then?
                My Snippets
                -> PopUpChunk v1.0
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                It’s supposed to use the TRUNCATE query, but I’m not sure what would happen if there were corrupted entries. But from the screenshot you sent, it’s not actually empty, just no valid records. You also need to remove the entries from the web_user_attributes table; that’s the one with the email address and other information.

                You might also try the different options at the bottom of the Operations tab, such as repair or optimize or flush.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 28033
                  • 925 Posts
                  Quote from: sottwell at Feb 12, 2008, 12:24 AM

                  It’s supposed to use the TRUNCATE query, but I’m not sure what would happen if there were corrupted entries. But from the screenshot you sent, it’s not actually empty, just no valid records. You also need to remove the entries from the web_user_attributes table; that’s the one with the email address and other information.

                  You might also try the different options at the bottom of the Operations tab, such as repair or optimize or flush.

                  I’ve attached another image. It’s odd, because the database is saying there’s no data at all, so why is WLPE saying a username exists?

                  The only thing I do not have access to is the Flush command --- should I see if my webhost can allow access to it? All of the other options fail to "grey out" the Browse tab.

                  (BTW, thanks for all of your help so far. smiley)
                    My Snippets
                    -> PopUpChunk v1.0
                    • 4310
                    • 2,310 Posts
                    Just to be sure, why not drop the table and then recreate it?
                      • 7231
                      • 4,205 Posts
                      Quote from: bunk58 at Feb 12, 2008, 07:27 AM

                      Just to be sure, why not drop the table and then recreate it?
                      That’s my suggestion as well. Looks like there is something screwy going on there.
                        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                        Something is happening here, but you don't know what it is.
                        Do you, Mr. Jones? - [bob dylan]