"DB error, create SQL table before"

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Trash_Bandatcoot, Jul 25, 2018.

  1. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    I just wan't to learn how to manage an online chat. I found a source, added that to my website, but it gives this error anytime I open or refresh the page:

    DB error, create SQL table before
    This is the site: http://choconut.epizy.com/

    I found an answer and he said that I need to make sure I already configured my "DB" (which I assume stands for DataBase) details in the 'inc/chat.inc.php' file.

    This is the source https://www.script-tutorials.com/demos/6/source.zip and I assume this problem is pinpointed to 'sql.sql' and 'chat.inc.php'.
    Can someone help me fix this issue?
    Thanks!
     
  2. BigPanda

    BigPanda GBAtemp Regular

    Member
    3
    Jul 18, 2016
    Belgium
    On the chat.inc.php you have setup the value for $this->sDbName = 'database_name';

    You need to ensure that you have created a database inside your mysql server that is named the same as the word written between single quotes.

    You might want to understand the basic of mySQL and have a minimum understanding for reading (not coding) PHP files.

    https://www.w3schools.com/
     
    Last edited by BigPanda, Jul 25, 2018
  3. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Something like this?
    Still didn't work, the error still displayed on the site.
     

    Attached Files:

    • php.png
      php.png
      File size:
      7.6 KB
      Views:
      38
  4. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    Looks like it wants you to use the query provided in sql.sql to create a table to work with.
    In your database run the sql.sql file or run the following query:
    Code:
    CREATE TABLE `s_chat_messages` (
    `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
    `user` VARCHAR( 255 ) NOT NULL ,
    `message` VARCHAR( 255 ) NOT NULL ,
    `when` INT( 11 ) NOT NULL ,
    PRIMARY KEY ( `id` )
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    EDIT: You don't need to name your database "sql.sql". You basically make your database and name it anything e.g. "simplechat", you assign a database user to that database and then you'd use "simplechat" (or whatever you called your database) in place of "database_name" in chat.inc.php then in place of "username" you'd have the user you assigned to the database and then for "password" you'd put that users password. You should then use the query I mentioned above on the database you made and then "SimpleChat" should have no problem communicating with the database.
     
    Last edited by fadx, Jul 25, 2018
  5. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    It still doesn’t work.
    I changed it to “ChocoNut.sql”, made sure everything in the PHP files was attatched to it, and it still gives the same error.

    It doesn’t give me the options to run a query or file, only to edit, delete rename or add files.
     
  6. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    Do you have an SQL database setup? The .sql file is not the database, it's a file that you'll use to tell the a database you already have what table it should make.

    In your web panel there should be a section called "DATABASES", within that section click on "MySQL Databases".
    Enter a name for the database e.g. simplechat.
    It'll make the database and the information will be below.
    Some example information would be:
    DB Name: epiz_12345678_simplechat
    User Name: epiz_12345678
    Password: "YOUR_CPANEL_PASS"
    HostName: sql123.epizy.com

    With that information you'd open up chat.inc.php and change the following:
    Code:
        function SimpleChat() {
            //mysql_connect("localhost","username","password");
            $this->sDbName = 'database_name';
            $this->sDbUser = 'username';
            $this->sDbPass = 'password';
        }
    to this:
    Code:
        function SimpleChat() {
            //mysql_connect("localhost","username","password");
            $this->sDbName = 'epiz_12345678_simplechat';
            $this->sDbUser = 'epiz_12345678';
            $this->sDbPass = 'YOUR_CPANEL_PASS';
        }
    After you've done that, you'll want to replace every instance of "localhost" to the host name, which in this example would be "sql123.epizy.com".

    Once you've done all this you'll want to go back to your websites control panel and under "DATABASES" select "phpMyAdmin".
    Once here click "Connect now!" next to the database you just created.
    You'll be brought to a page with tabs at the top, click the tab that says "SQL".
    Inside that box put the following:
    Code:
    CREATE TABLE `s_chat_messages` (
    `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
    `user` VARCHAR( 255 ) NOT NULL ,
    `message` VARCHAR( 255 ) NOT NULL ,
    `when` INT( 11 ) NOT NULL ,
    PRIMARY KEY ( `id` )
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    Then at the bottom right click "Go".
    It should hopefully say something like "Your SQL query has been executed successfully ( Query took 0.0123 sec )" at the top of the page.
    You can then click the "Structure" tab at the top and hopefully a table should be there called "s_chat_messages".
    Hopefully your website should now be able to communicate with the database.
     
    Last edited by fadx, Jul 25, 2018
  7. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    I think this will do the job for me, but I can't even find the 'DATABASES' button because everything is an icon and it does not open up database settings.
     
  8. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    "DATABASES" isn't a button, it's the name of the section. The section I'm talking about is like this:
    https://i.imgur.com/LQsl9cK.png
     
  9. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Oh,
    I accessed that panel yesterday and for whatever reason it doesn't work anymore.
    Anytime I try it says it was unable with the info I gave. I tried relogging in, and it doesn't seem to send me a mail for a password reset either.

    I'm now completely lost for no reason :(

    Edit: And now I completely lost access. Just another day where nothing works!
     
    Last edited by Trash_Bandatcoot, Jul 25, 2018
  10. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
  11. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Thanks, I finally got access, Epiz started to spam my junk because I requested 3 mails :/
    Allright, I'm going a few posts back reading the solution
     
  12. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    This is what I wrote, still doesn't work.
     
  13. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    Did you execute the query I posted in phpMyAdmin to create the table?

    Also there's multiple of instances of localhost that would need to be replaced with the sql303.epizy.com

    EDIT: This will make it easier.
    Copy all the text here: https://pastebin.com/raw/fvW1Ah2v
    Delete all the text in chat.inc.php and replace it with the text you copied.
    On lines 15, 16, 17 and 18 replace 'HOST', 'DATABASE', 'USERNAME' and 'PASSWORD' with the correct information.

    For whatever reason the example code they give you doesn't take into account that you might not be using localhost for the database and therefore it doesn't create a host variable to be used. If you use the code from that pastebin it should just be as simple as putting the correct info on those 4 line.
     
    Last edited by fadx, Jul 25, 2018
  14. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Yes, I executed the query, and double checked that s_chat_messages is there.
    It is.
    I will now replace the text I got in Pastebin but it's such a hassle.
    I can't change the password and when I accidently put in the wrong info it automaticly blocks and I can't login for 5 minutes.
     
  15. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Thank you so much!
    I finally got it to work!
    Just go to http://choconut.epizy.com/ and you see 3 messages we're made by User1.
    You can come in too if you want as User2, I'll add custom users as soon I know how to edit them (shouldn't be too hard)
     
  16. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    That's great to hear, glad I could help!
     
    Coto and Trash_Bandatcoot like this.
  17. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Also, I'm wondering if you could help me with this:
    The accounts are User1, User2 and User3 and all share a bad password.
    I want to make my own account but I can't find anywhere in any file how to edit, delete or add users.
    All I could find was this in login.inc.php:
     
  18. fadx

    fadx Filthy Cheater

    Member
    3
    Sep 15, 2016
    United Kingdom
    I'm really not sure, I would check the website you got that source from and see if they also have a user system that you could use to register accounts etc. I actually don't really know any PHP but I know a good bit of C# and I've worked with databases before so I was able to piece together what the source code was looking for. Unfortunately I don't really know how you'd manage user creation etc.
     
  19. Trash_Bandatcoot
    OP

    Trash_Bandatcoot GBAtemp Regular

    Member
    2
    Jul 14, 2018
    Netherlands
    Ok, guess I have to contact the Source creator

    — Posts automatically merged - Please don't double post! —

    Fun fact:
    The users are hardcoded, so despite finally working, I can't add more users, meaning I have to find a new PHP chat.