PHP probleem?

Gestart doorJordyvc10 reacties34 weergaven

11 berichten · pagina 1 van 1

Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey,

Ik ben bezig met PHP te leren en ik heb een scriptje gemaakt dat hij gewoon naam en voormaan in de database stopt. Maar nu is er een error, jah error? Dit komt erop "No database selected" Als ik naar de pagina ga.

Dit is mijn code:

<html>
<head><title> TEST </title></head>
<body>
[COLOR= #0000BB]<?php
$con[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"jordyvc_db"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"*****"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]Sorry, wij kunnen niet verbinden met de database![/COLOR][COLOR= #007700]);
        }[/COLOR]

[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"DB"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$con[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"INSERT INTO personen (voornaam, achternaam)
VALUES ($_POST[voornaam],$_POST[achternaam])"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$con[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]Problemen:[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"U bent toegevoegd aan de database!"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/mysql_close"]mysql_close[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700])[/COLOR]
?>
        
<form action="" method="POST">
        Naam: <input type="text" name="naam" />
        Achternaam: <input type="text" name="achternaam" />
        <input type="submit" value="Oke" />
</form>
</body>
</html>


Weet iemand wat er fout is?

Mvg,
Jordyvc
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<html>
<head><title> TEST </title></head>
<body>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// Database gegevens. 
// HOST, Meestal localhost[/COLOR]
[COLOR= #0000BB]$db_host[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// Gebruikersnaam.[/COLOR]
[COLOR= #0000BB]$db_user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]jordyvc_db[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// Wachtwoord.[/COLOR]
[COLOR= #0000BB]$db_pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]jewachtwoord[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// Database naam.[/COLOR]
[COLOR= #0000BB]$db_name[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Jedbnaam[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #FF8000]// Controle of alles correct is ingesteld.[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$db_host[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$db_user[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$db_pass[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Kon geen verbinding maken met de database...<br>FOUTCODE: ERCON.[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$db_name[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Kon geen database vinden...<br>FOUTCODE: ERDB[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$con[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO 
                    berichtenbalk(
                        voornaam, 
                        achternaam
                    ) 
                    VALUES (
                        "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]voornaam[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]",
                        "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]achternaam[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]"
                    );
                    "[/COLOR][COLOR= #007700])[/COLOR]or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
                    

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"U bent toegevoegd aan de database!"[/COLOR][COLOR= #007700];
}[/COLOR][URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
 [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();   
}[/COLOR]



[URL="http://www.php.net/mysql_close"]mysql_close[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700])[/COLOR]
?>
        
<form action="" method="POST">
        Naam: <input type="text" name="naam" />
        Achternaam: <input type="text" name="achternaam" />
        <input type="submit" value="Oke" />
</form>
</body>
</html>


Probeer dit is beveiligd tegen sqli.
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat was mijn fout?
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je had geen database meegegeven wink
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
En je database was hackable
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nog een ander probleem. emoNu als ik de pagina open dan wordt hij al toegevoegd. Dus twee lege vakken.

toevoeging op 26 maart 2012, 18:07:06:
En hij plaatst de voornaam niet in de DB?

toevoeging op 26 maart 2012, 181811:
Dat eerste probleem is trg opgelost, maar hij plaatst alleen de achternaam in de DB?
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Doe dit:

<form action="" method="POST">
        Naam: <input type="text" name="voornaam" />
        Achternaam: <input type="text" name="achternaam" />
        <input type="submit" value="Oke" />
</form>
</body>
</html>
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Doe dit:

<form action="" method="POST">
        Naam: <input type="text" name="voornaam" />
        Achternaam: <input type="text" name="achternaam" />
        <input type="submit" value="Oke" />
</form>
</body>
</html>
Ja bedankt! Had het juist ook door biggrin
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Eerdere citaten tonen
Maartenl schreef:
Je leert beter direct MySQLi
Is een kleine aanpassing winkTut : http://www.phphulp.nl/php/tutorial/overig/mysqli/499/ (OOP)

Ik denk niet dat het enig verschil zou maken in dit geval.
Neen, maar MySQLi is beter en meer up to date dan MySQL en je leert het dus beter direct zo dan achteraf je manier aan te passen.
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