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:
Weet iemand wat er fout is?
Mvg,
Jordyvc
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
Tut :
Nu als ik de pagina open dan wordt hij al toegevoegd. Dus twee lege vakken.
11: