Page 1 of 1

help need with error

Posted: Mon Jun 27, 2011 8:28 am
by reconoistre
this is my code,

<?php


include('Wizard.php');

class FieldMap extends Wizard{
public function getPageTitle(){
return "Map DB Fields";
}

public function index(){
$this->fieldMapping();
}

public function deleteMapping(){
if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
@unlink(PATH_DIR."dbMaps/".$_GET[dbID].".php");
}

$this->myDBObj->delete("databases" , "id = '$_GET[dbID]'");
echo $this->myDBObj->getLastError();
$this->myDBObj->delete("sites" , "dbid = '$_GET[dbID]'");
header("Location: .");
}

public function fieldMapping(){
if(count($_POST)){
$this->saveMap();
}

$fieldsData = array();
if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
include(PATH_DIR."dbMaps/".$_GET[dbID].".php");
}

$tableFields = array();
{
$tables = $this->dbObj->getTables();
foreach($tables as $table){
$tableFields[$table] = $this->dbObj->getFields($table);
}
$data[tableFields] = $tableFields;
$data[PKs] = $this->dbObj->getPKs();
$data[fieldsData] = $fieldsData;

$this->loadTemplate("FieldMap" , $data);
}

function saveMap(){
$tables = $this->dbObj->getTables();
foreach($tables as $table){
$fields = $this->dbObj->getFields($table);
foreach($fields as $field){
$_DATA['data']['tables'][$table]['fields'][] = $field;
$fldName = $table."_".$field[Field];
if($field["PK"]=="PRI"){
$_DATA['data']['tables'][$table]['primary'] = $field[Field];
}

if($_POST["fk_$fldName"] != ""){
$_DATA['data']['tables'][$table]['links'][$field[Field]] = $_POST["fk_$fldName"];
}


{

$fileContent = var_export($_DATA['data'] , true);
$fileContent = "<?\n\$fieldsData = $fileContent ; \n?>";

$fp = fopen(PATH_DIR."dbMaps/".$_GET[dbID].".php" , "w");
fwrite($fp , $fileContent);
fclose($fp);

header("Location: .");$this->funcPath("MainPage");
}
?>
this is my error message

Parse error: syntax error, unexpected $end in /home/j05ayrw/public_html/viz/Classes/Wizards/FieldMap.php on line 77

i got something wrong and thisd is driving me nuts. any suggestions most welcome!

Re: help need with error

Posted: Mon Jun 27, 2011 12:55 pm
by Jade
Look at line 66, you have an opening bracket without a conditional statement.

Re: help need with error

Posted: Mon Jun 27, 2011 5:28 pm
by superdezign
Jade wrote:Look at line 66, you have an opening bracket without a conditional statement.
No, that's perfectly legal. Odd, but legal.

Line 77 is the end of the file. The error stating "unexpected end" means that the end came without warning. This is almost always the result of unmatched braces (though sometimes the result of unmatched quotation marks, HEREDOC syntax, parentheses, or braces). In order to fix it, try properly indenting your code.

What you have is this:

Code: Select all

<?php


include('Wizard.php'); 

class FieldMap extends Wizard{
    public function getPageTitle(){
        return "Map DB Fields";
    }

    public function index(){
        $this->fieldMapping();
    }

    public function deleteMapping(){
        if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
            @unlink(PATH_DIR."dbMaps/".$_GET[dbID].".php");
        }

        $this->myDBObj->delete("databases" , "id = '$_GET[dbID]'");
        echo $this->myDBObj->getLastError();
        $this->myDBObj->delete("sites" , "dbid = '$_GET[dbID]'");
        header("Location: .");
    }

    public function fieldMapping(){
        if(count($_POST)){
            $this->saveMap();
        }

        $fieldsData = array();
        if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
            include(PATH_DIR."dbMaps/".$_GET[dbID].".php");
        }

        $tableFields = array();
        {
            $tables = $this->dbObj->getTables();
            foreach($tables as $table){
                $tableFields[$table] = $this->dbObj->getFields($table);
            }
            $data[tableFields] = $tableFields;
            $data[PKs] = $this->dbObj->getPKs();
            $data[fieldsData] = $fieldsData;

            $this->loadTemplate("FieldMap" , $data);
        }    

        function saveMap(){
            $tables = $this->dbObj->getTables();
            foreach($tables as $table){
                $fields = $this->dbObj->getFields($table);
                foreach($fields as $field){
                    $_DATA['data']['tables'][$table]['fields'][] = $field;
                    $fldName = $table."_".$field[Field];
                    if($field["PK"]=="PRI"){
                        $_DATA['data']['tables'][$table]['primary'] = $field[Field];
                    }

                    if($_POST["fk_$fldName"] != ""){
                        $_DATA['data']['tables'][$table]['links'][$field[Field]] = $_POST["fk_$fldName"];
                    }    


                    {

                        $fileContent = var_export($_DATA['data'] , true);
                        $fileContent = "<?\n\$fieldsData = $fileContent ; \n?>";

                        $fp = fopen(PATH_DIR."dbMaps/".$_GET[dbID].".php" , "w");
                        fwrite($fp , $fileContent);
                        fclose($fp);

                        header("Location: .");$this->funcPath("MainPage");
                    }
?>
What you want (maybe.. I can't be sure) is this:

Code: Select all

<?php


include('Wizard.php'); 

class FieldMap extends Wizard{
    public function getPageTitle(){
        return "Map DB Fields";
    }

    public function index(){
        $this->fieldMapping();
    }

    public function deleteMapping(){
        if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
            @unlink(PATH_DIR."dbMaps/".$_GET[dbID].".php");
        }

        $this->myDBObj->delete("databases" , "id = '$_GET[dbID]'");
        echo $this->myDBObj->getLastError();
        $this->myDBObj->delete("sites" , "dbid = '$_GET[dbID]'");
        header("Location: .");
    }

    public function fieldMapping(){
        if(count($_POST)){
            $this->saveMap();
        }

        $fieldsData = array();
        if(is_file(PATH_DIR."dbMaps/".$_GET[dbID].".php")){
            include(PATH_DIR."dbMaps/".$_GET[dbID].".php");
        }

        $tableFields = array();
        {
            $tables = $this->dbObj->getTables();
            foreach($tables as $table){
                $tableFields[$table] = $this->dbObj->getFields($table);
            }
            $data[tableFields] = $tableFields;
            $data[PKs] = $this->dbObj->getPKs();
            $data[fieldsData] = $fieldsData;

            $this->loadTemplate("FieldMap" , $data);
        }    
    }

    function saveMap(){
        $tables = $this->dbObj->getTables();
        foreach($tables as $table){
            $fields = $this->dbObj->getFields($table);
            foreach($fields as $field){
                $_DATA['data']['tables'][$table]['fields'][] = $field;
                $fldName = $table."_".$field[Field];
                if($field["PK"]=="PRI"){
                    $_DATA['data']['tables'][$table]['primary'] = $field[Field];
                }

                if($_POST["fk_$fldName"] != ""){
                    $_DATA['data']['tables'][$table]['links'][$field[Field]] = $_POST["fk_$fldName"];
                }    



                $fileContent = var_export($_DATA['data'] , true);
                $fileContent = "<?\n\$fieldsData = $fileContent ; \n?>";

                $fp = fopen(PATH_DIR."dbMaps/".$_GET[dbID].".php" , "w");
                fwrite($fp , $fileContent);
                fclose($fp);

                header("Location: .");$this->funcPath("MainPage");
            }
        }
    }
}
?>
However, I didn't take the time to read any of your code, I simply looked at the proper indentation.

Re: help need with error

Posted: Tue Jun 28, 2011 9:31 am
by Jade
superdezign wrote:No, that's perfectly legal. Odd, but legal.
Really? Huh, that's strange. You'd think PHP would cry wolf at something like that but I guess as long as they're a matching set it'll parse without problems.

Re: help need with error

Posted: Tue Jun 28, 2011 10:02 am
by VladSun
As far as I know in some languages defining a block:

Code: Select all

{
   int i =0;
   ....
}
introduces a local scope. It's pretty much legal, though not sure what are the benefits of using it in PHP :)