PHP OOP Probleem

Gestart doorLodwijk4 reacties15 weergaven

5 berichten · pagina 1 van 1

Lodwijk

Lid · Topicstarter

Berichten
104
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo one2xsers

Ik ben nu bezig aan me eerste OOP php script,Maar ik loop steeds op deze probleem

Parse error: syntax error, unexpected }

Mijn code is:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]include/config.php[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/class"]class[/URL] muntjes [COLOR= #007700]{[/COLOR]


[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]() 

{[/COLOR]
        [COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] DB_Class[COLOR= #007700]();
}[/COLOR]

[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] invoegen_muntjes[COLOR= #007700]([/COLOR][COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700]) 
{[/COLOR]

[COLOR= #0000BB]$muntjesinvoegen[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO leden (muntjes) VALUES ($muntjes)"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[0-9]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700])
}}[/COLOR]


?>


weten jullie de oplossing Laat dan ff een bericht achter en Voor tips sta ik ook open wink
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Lijn het eerst eens netjes uit, dan zie je direct wat er fout is.

Als je ergens in je script {{ of }} ziet dan weet je al dat je het niet goed uitgelijnd hebt.
0
Lodwijk

Lid · Topicstarter

Berichten
104
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Lijn het eerst eens netjes uit, dan zie je direct wat er fout is.

Als je ergens in je script {{ of }} ziet dan weet je al dat je het niet goed uitgelijnd hebt.
Ookee gedaan Nu krijg ik hem zo

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]include/config.php[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/class"]class[/URL] muntjes
 [COLOR= #007700]{[/COLOR]

[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]() 

{[/COLOR]
        [COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] DB_Class[COLOR= #007700]();
}[/COLOR]

[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] invoegen_muntjes[COLOR= #007700]([/COLOR][COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700]) 
{[/COLOR]

[COLOR= #0000BB]$muntjesinvoegen[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO leden (muntjes) VALUES ($muntjes)"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[0-9]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700]){



}


}[/COLOR]
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
A. Dit is geen OOP dit is een class. Classes zijn niet meteen OOP.
B. Dat is geen uitlijnen.

De rest van mijn opmerkingen staan in de code:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]include/config.php[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/class"]class[/URL] muntjes 
[COLOR= #007700]{[/COLOR]
    [COLOR= #FF8000]// Je maakt hier wel een var $db aan, maar deze bestaat enkel binnen de construct functie voor zover ik weet. Je zult hem buiten deze functie dus niet kunnen gebruiken.[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]()  {[/COLOR]
        [COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] DB_Class[COLOR= #007700]();
    }[/COLOR]

    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] invoegen_muntjes[COLOR= #007700]([/COLOR][COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$muntjesinvoegen[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO leden (muntjes) VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$muntjes[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]")"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #FF8000]// Je functie stopt na een return ...[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();[/COLOR]
        
        [COLOR= #FF8000]// Dit zal hij dus nooit uitvoeren
        // Bovendien ben je een ) vergeten[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[0-9]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$muntjes[/COLOR][COLOR= #007700])) {

        }
        
    }[/COLOR] [COLOR= #FF8000]// Deze acolade was je vergeten[/COLOR]

[COLOR= #007700]}[/COLOR]
0
Lodwijk

Lid · Topicstarter

Berichten
104
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zeer Dank voor jullie Hulp

Groetjes Lodwijk
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren