0

I am working on this code on my PHP server and I keep getting this error but don't know why. Could someone please help. I looked for missing items but I can't find anything.

Parse error: syntax error, unexpected '{' in /home4/johnwilliams/public_html/core/init.inc.php on line 34

<?php

session_start();

error_reporting(E_ALL);

include_once($_SERVER['DOCUMENT_ROOT']."/config/db.inc.php");

foreach ($C as $name => $val) {

    define($name, $val);
}

foreach ($B as $name => $val) {

    define($name, $val);
}

$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
$dbo = new PDO($dsn, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

//$dbo = new PDO($dsn, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"));


function autoload($class) {
    $filename = $_SERVER['DOCUMENT_ROOT']."/class/class.".$class.".inc.php";

    if (file_exists($filename)) {

        include_once($filename);
    }
}

ini_set('session.cookie_domain', APP_HOST);
session_set_cookie_params(0, '/', APP_HOST);

$helper = new helper($dbo);
$auth = new auth($dbo);

static function clearText($text); {

$text = trim($text);
$text = strip_tags($text);
$text = htmlspecialchars($text);

return $text;
}

static function clearInt($value); {

$value = intval($value);

return $value;
}

Line 34 is below:

function autoload($class) {
Tordek
  • 10,628
  • 3
  • 36
  • 67

3 Answers3

1

You are getting the syntax wrong. In PHP you do not add a semicolon ; after a if() or a function foo() but semicolons within the curly braces {} of a function or if statement are allowed.

static function clearText($text) { //<-- Remove semicolon
    $text = trim($text);
    $text = strip_tags($text);
    $text = htmlspecialchars($text);

    return $text;
}

static function clearInt($value) { //<--Remove semicolon
    $value = intval($value);

    return $value;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
0

You've got semicolons after your static function statements in a couple of places that are causing the issue. For example:

static function clearText($text); {

Should be

static function clearText($text) {
John C
  • 8,223
  • 2
  • 36
  • 47
0

Use this code.

<?php
    session_start();

    error_reporting(E_ALL);

    include_once($_SERVER['DOCUMENT_ROOT']."/config/db.inc.php");

    foreach ($C as $name => $val) {

        define($name, $val);
    }

    foreach ($B as $name => $val) {

        define($name, $val);
    }

    $dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
    $dbo = new PDO($dsn, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

    //$dbo = new PDO($dsn, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"));


    function autoload($class) {
        $filename = $_SERVER['DOCUMENT_ROOT']."/class/class.".$class.".inc.php";

        if (file_exists($filename)) {

            include_once($filename);
        }
    }

    ini_set('session.cookie_domain', APP_HOST);
    session_set_cookie_params(0, '/', APP_HOST);

    $helper = new helper($dbo);
    $auth = new auth($dbo);

    function clearText($text) {

    $text = trim($text);
    $text = strip_tags($text);
    $text = htmlspecialchars($text);

    return $text;
    }

    function clearInt($value) {

    $value = intval($value);

    return $value;
    }
?>

Thanks Amit

Amit Shah
  • 1,380
  • 1
  • 10
  • 19