Php Mysql - Error in my Error-Logging function

Asked

Viewed 11 times

1

I am trying to build a log system for php-mysql errors

In my createtable() function I call errorLog() when I need to record an error.

// Database - CREATE TABLES
    public function createTables($sql) {
        if ($this->connection->query($sql) === TRUE) {
            echo "Tables created successfully<br/>";
        } else {
            $msg = "ERROR - Impossible to create DB";
            $this->errorLog($msg);
        }
    }
    // ****

And here’s my errorLog function():

// error logging
    public function errorLog($msg) {
        echo $msg."<br/>";
        $user = '';
        $date = date("d/m/Y H:i:s a", time());
        $error = $this->connection->error;
        $state = 1;
        $sql = "INSERT INTO `zapp_logs` (`id`, `user`, `date`, `error`, `state`) VALUES (NULL, '$user', '$date', '$error', '$state')";
        if ($this->connection->query($sql) === TRUE) {
            echo "error logged<br/>";
        } else {
            echo "error not logged: " . $this->connection->error . "<br/>";

        }

    }

(I know the code isn’t perfect, I’m still trying to improve)

Please ignore the fact that there are valueless variables, I’m still in the development phase

My problem is in errorlog() function. Gives a syntax error. I’ve tried several things but can’t find the error. The code seems to run up to $sql

Thanks for your help and I appreciate any code improvement you might suggest.

Regards

  • You can believe :) The installer only serves to create the database, and to create test information, then the installer folder itself will be removed from the final software. and users' queries will pass another function.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.