help need with error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
reconoistre
Forum Newbie
Posts: 1
Joined: Mon Jun 27, 2011 8:20 am

help need with error

Post 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!
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: help need with error

Post by Jade »

Look at line 66, you have an opening bracket without a conditional statement.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: help need with error

Post 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.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: help need with error

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: help need with error

Post 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 :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply