De parameters heb ik al dus daar ligt het in ieder geval niet aan :P
<?php
//DB connection string en functions
include "db.php";
include "f.php";
if(isset($_POST['btnSave'])){
createRecord($_POST['voornaam'], $_POST['achternaam'], $_POST['leeftijd']);
}
if(isset($_POST['btnList'])){
echo listRecords();
}
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h2>Insert new employee</h2>
<table class="tablestyle">
<form method="post" action="dbexamplea.php">
<tr>
<td>Voornaam</td>
<td><input type="text" name="voornaam"></td>
</tr>
<tr>
<td>Achternaam</td>
<td><input type="text" name="achternaam"></td>
</tr>
<tr>
<td>Leeftijd</td>
<td><input type="text" name="leeftijd"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnSave" value="Save">
<input type="submit" name="btnList" value="List Records">
<form method="post" action="<?php $_PHP_SELF ?>">
</td>
</tr>
</form>
</table>
</body>
</html>
____________________________________________________
<?php
function listRecords()
{
//Create database connection and check for errors
if(!$con = mysqli_connect(HOSTNAME, USERNAME, PASSWORD, DBNAME)){
die("Fout bij verbinden met database!");}
//Construct SQL query
$sqlquery = "Select * from studenten";
//Execute SQL query against MySQL DB and check for errors
if(!$result = mysqli_query($con, $sqlquery)){
die("Fout in query!");
}
//Create table structure
$tmp = "<table class='tablestyle'>
<tr>
<td>Voornaam</td>
<td>Achternaam</td>
<td>Leeftijd</td>
<td></td>
<td></td>
</tr>";
//Loop through array data (result set)
while($row = mysqli_fetch_array($result)){
$tmp = $tmp . '<tr>
<td>' . $row['voornaam'] . '</td>
<td>' . $row['achternaam'] . '</td>
<td>' . $row['leeftijd'] . '</td>
<td><input type="button" value="Edit" onclick="edit"></td>
<input name="delete" type="submit" id="delete" value="Delete">
</tr>';
}
//Close html table
$tmp = $tmp . '</table>';
return $tmp;
}
function createRecord($v, $a, $l)
{
//Create database connection and check for errors
if(!$con = mysqli_connect(HOSTNAME, USERNAME, PASSWORD, DBNAME)){
die("Fout bij verbinden met database!");
}
//Construct SQL query
$sqlquery = "insert into studenten (voornaam, achternaam, leeftijd)
values('$v','$a','$l')";
//Execute SQL query against MySQL DB and check for errors
if(!$result = mysqli_query($con, $sqlquery)){
die("Fout in query!");
}
//Done. Now show a confirmation
echo "<script>alert('Record is succesvol opgeslagen!');</script>";
}
//Delete records.
$user = $_POST['user'];
03
$sql = "DELETE FROM users WHERE user_name = $d";
04
$result = mysql_query($sql);
?>