ik heb een 'gewoon' formulier gemaakt in html en nu wil ik graag de ingevulde velden bij het versturen in een database zien te krijgen, en als mensen op 'verstuur' drukken dat er een redirect komt naar een bedankt pagina.
Heeft iemand voor mij een werkend voorbeeld ergens?
alvast heel erg bedankt!Marcone
http://www.w3schools.com/php/php_mysql_intro.asp
Ik kan zo 1,2,3 namelijk niets vinden?
Pest is dat we niet zomaar eventjes werkende code kunnen geven omdat we gewoon niet weten hoe jouw database en je code in elkaar steken! Ik kan je mijn code wel geven, maar daar heb je niets aan omdat mijn database heel anders is opgebouwd, evenals jouw PHP+HTML code.
Heb je de database al klaar staan? Is er al een tabel ingericht? Zo ja, wat zijn de veldnamen van de tabel en het formulier, dan kunnen we je vast wel helpen.
Het gaat mij dus om de broncode die verbinding maakt met de mysql database, en een functie die na het versturen een nieuwe statische html pagina laadt.
ik zoek wel even verder, dan zal ik vast iets vinden.
thxMarcone
Insert Data From a Form Into a DatabaseNow we will create an HTML form that can be used to add new records to the "Persons" table.Here is the HTML form:<html><body><form action="insert.php" method="post">Firstname: <input type="text" name="firstname" />Lastname: <input type="text" name="lastname" />Age: <input type="text" name="age" /><input type="submit" /></form></body></html>When a user clicks the submit button in the HTML form in the example above, the form data is sent to "insert.php".The "insert.php" file connects to a database, and retrieves the values from the form with the PHP $_POST variables.Then, the mysql_query() function executes the INSERT INTO statement, and a new record will be added to the "Persons" table.Here is the "insert.php" page:<?php<br>$con = mysql_connect("localhost","peter","abc123");<br>if (!$con)<br> {<br> die('Could not connect: ' . mysql_error());<br> }<p>mysql_select_db("my_db", $con);<p>$sql="INSERT INTO Persons (FirstName, LastName, Age)<br>VALUES<br>('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";<p>if (!mysql_query($sql,$con))<br> {<br> die('Error: ' . mysql_error());<br> }<br>echo "1 record added";<p>mysql_close($con)<br>?>
Now we will create an HTML form that can be used to add new records to the "Persons" table.
Here is the HTML form:
<html><body>
<form action="insert.php" method="post">Firstname: <input type="text" name="firstname" />Lastname: <input type="text" name="lastname" />Age: <input type="text" name="age" /><input type="submit" /></form>
</body></html>When a user clicks the submit button in the HTML form in the example above, the form data is sent to "insert.php".
The "insert.php" file connects to a database, and retrieves the values from the form with the PHP $_POST variables.
Then, the mysql_query() function executes the INSERT INTO statement, and a new record will be added to the "Persons" table.
Here is the "insert.php" page:
<?php<br>$con = mysql_connect("localhost","peter","abc123");<br>if (!$con)<br> {<br> die('Could not connect: ' . mysql_error());<br> }<p>mysql_select_db("my_db", $con);<p>$sql="INSERT INTO Persons (FirstName, LastName, Age)<br>VALUES<br>('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";<p>if (!mysql_query($sql,$con))<br> {<br> die('Error: ' . mysql_error());<br> }<br>echo "1 record added";<p>mysql_close($con)<br>?>
De statische vervolgpagina voeg je natuurlijk gewoon aan het tweede documentje (insert.php) toe.
Maar misschien kan je beter wat meer in detail treden, dan kan ik je daarop geënte code geven, zie het commentaar van CC!
marcone om 15:25, 14-06-2010de database in nu nog leeg. Mijn html form heeft veldnamen. Ik ga nu dus corresponderende tabels aanmaken in mijn database.Het gaat mij dus om de broncode die verbinding maakt met de mysql database, en een functie die na het versturen een nieuwe statische html pagina laadt.ik zoek wel even verder, dan zal ik vast iets vinden.thxMarcone
Haastige spoed is niet altijd goed en bovendien is meer info (en eventuele html code van je formulier) handig voor mensen die je willen helpen...
@philiphoutust: ik heb hier gekeken, zowat hetzelfde als jouw link:
http://php.about.com/od/phpbasics/ss/mysql_files.htm