0
<?php
    ## Hi I don't know whats wrong with my code im trying to create a  
       database and three simple tables using php and mySQL, I try to
       run it on a page on my local server and its giving this error 
       for when im trying to end the php code(?>, have no clue why
       but stack decided to put it as a comment at the end)
       This is the error : Parse error: syntax error, unexpected end 
       of file in /opt/lampp/htdocs/Gymbud/DatabaseConnection.php on 
       line 58  ##
    $db_user = ‘root’;
    $db_pass = ‘root’;
    $db_name = ‘Gymbud’;
    $db_host = '192.168.64.2';

    $mysqli = new mysqli ($db_host, $db_user , $db_pass , $db_name);


    // This code essentially just checks if we’re connected to the database or not and if not it prints an error message to the screen and exits the application
    if ($mysqli -> connect_errno) {
        printf( "Connect Failed: %s\n" . $mysqli -> connect_error);
        exit();
    }


   //This code just creates a table for the object (Posts)
    $Post_table = 
            "CREATE TABLE IF NOT EXISTS Gymbud (
                    ID bigint (20) UNSIGNED NOT NULL AUTO_INCREMENT,
                    Post_title text NOT NULL,
                    Post_content longtext NOT NULL,
                    Post_name varchar (20) NOT NULL,
                    Post_date date time NOT NULL,
                    PRIMARY KEY (ID)
                )” ;


            if ($mysqli->query($Post_table) === TRUE) {
                printf(“Post Table successfully created.\n”);
                } 

// Sorry I have to include more details but I don't really know what more to say if anyone can help id be much appreciated // This code essentially just creates a meta table for the object table above

    $Post_meta_table = 
                “CREATE TABLE IF NOT EXISTS Post_meta (
                    Meta_ID bigint (20) UNSIGNED NOT NULL 
                    AUTO_INCREMENT,
                    Post_ID bigint (20) UNSIGNED NOT NULL,
                    Meta_key varchar (255),
                    Meta_value longtext,
                    PRIMARY KEY (Meta_ID)
                )”;


            if ($mysqli->query($Post_Meta_table) === TRUE) {
                printf(“Post Meta table successfully created.\n”);
                } 

               // This code essentially just creates a relationship 
                  table for the object table above 

    $Post_Tags_table = 
                “CREATE TABLE IF NOT EXISTS Post_Tag_Relationships (
                ID bigint (20) UNSIGNED NOT NULL AUTO_INCREMENT,
                Post_ID bigint (20) UNSIGNED  NOT NULL,
                Tag_ID bigint (20) UNSIGNED  NOT NULL,
                PRIMARY KEY (ID)
                )”;


            if ($mysqli->query($Post_Tags_table) === TRUE) {
                printf(“Post_Tags_Relationships table successfully  
                created.\n”);
            }

?>

Sorry I have to include more details but I don't really know what more to say if anyone can help id be much appreciated

  • You're probably missing a closing `}` or `"` somewhere in the file. – Nick Apr 15 '18 at 00:30
  • 3
    `” ` non standard double quote used all over the code? Not using a word processor to edit code are you – RiggsFolly Apr 15 '18 at 00:31
  • @RiggsFolly I'm using Visual Studio Code to edit the code and what do you mean about the double quotes? – Adam O Ceallaigh Apr 15 '18 at 00:49
  • @Nick I've looked over it line by line three times can't spot anything can you by any chance – Adam O Ceallaigh Apr 15 '18 at 00:49
  • 1
    What you have posted looks fine other than the double quotes (`“` and `”`) that @RiggsFolly mentioned. – Nick Apr 15 '18 at 00:54
  • @Nick, RiggsFolly sound lads I think I fixed that part of the error now as its not showing up I tried taking out the ending ?> and it worked automatically, any ideas why? I just went off a youtube video I saw not doing it – Adam O Ceallaigh Apr 15 '18 at 00:58
  • Well guys sorry to bother you again, I'm just wondering do you have any idea of how I can fix this one: Warning: mysqli::__construct(): (HY000/1130): Host '192.168.64.2' is not allowed to connect to this MariaDB server in /opt/lampp/htdocs/Gymbud/DatabaseConnection.php on line 7 Connect Failed: Host '192.168.64.2' is not allowed to connect to this MariaDB server – Adam O Ceallaigh Apr 15 '18 at 01:03
  • you cant use root user with mariadb by default you need to grant access, or better.. create a user which is not DBA. – Lawrence Cherone Apr 15 '18 at 01:18
  • @LawrenceCherone how do I go about this? – Adam O Ceallaigh Apr 15 '18 at 03:04
  • 1
    @AdamOCeallaigh Please read https://mariadb.com/kb/en/library/user-account-management/ on how to manage the user accounts in MariaDB. – Progman Apr 15 '18 at 08:01

0 Answers0