maar ik wil een admin gedeelte toevoegen waar je producten kan invoeren. Ik kan geen fouten vinden, php_errors is ook leeg er staat ook niks over in de logs folder. Ter verduidelijking ook wel belangrijk ik gebruik Wamp om mijn scripts te testen. Hieronder mijn code. Hij voert alles netjes uit en zet een afbeelding in de juiste map die hij de naam 0 geeft omdat er nog geen producten in de database staan. Heb net een product ingevoegd via phpmyadmin en die word netjes weergegeven door dezelfde code. Wat doe ik fout of kan het iets te maken hebben met de storage engine van phpmyadmin die MYISAM draait en de tabellen op INNODB dit heb ik ook veranderd en op MYISAM gezet maar werkt ook niet. Dus concreet mijn vraag waarom verschijnen er geen producten in de database. Alvast bedankt voor jullie hulp!
<?php // Session
session_start();
if (!isset($_SESSION["manager"])){
header("location: admin_login.php");
exit();
}
include ("login.php");
?>
<?php
// Clean data and verify input
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (!empty($_POST["voegToe"])) {
// Parse the form data and add inventory items to the system
// define variables and set to empty values
$product_naam=$prijs=$details=$fileField="";
$product_naamErr=$detailsErr=$prijsErr=$fileFieldErr="";
if (empty($_POST["product_naam"])) {
$product_naamErr = "Productnaam verplicht!";
} else {
$product_naam = test_input($_POST["product_naam"]);
if (!preg_match("/^[a-zA-Z]*$/",$product_naam)) {
$product_naamErr = "Alleen letters en spaties toegestaan";
}
}
if (empty($_POST["details"])) {
$detailsErr = "Beschrijving verplicht!";
} else {
$details = test_input($_POST["details"]);
if (!preg_match("/^[a-zA-Z]*$/",$details)) {
$detailsErr = "Alleen letters en spaties toegestaan";
}
}
if (empty($_POST["prijs"])) {
$prijsErr = "Prijs verplicht!";
} else {
$prijs = test_input($_POST["prijs"]);
if (!filter_var($prijs, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) {
$prijsErr = "Alleen cijfers toegestaan en ., toegestaan";
}
}
if (empty($_POST["fileField"])) {
$fileFieldErr = "Afbeelding toevoegen verplicht!";
} else {
$fileField = test_input($_POST["fileField"]);
if (!preg_match("/^[a-zA-Z0-9]*$/",$details)) {
$fileFieldErr = "Alleen letters en cijfers toegestaan";
}
}
// See if that product exists
$sql = "SELECT id FROM producten WHERE product_naam='$product_naam' LIMIT 1";
$result = mysqli_query($con,$sql);
$productMatch = mysqli_num_rows($result);
if ($productMatch > 0){
echo "U probeerd een duplicaat 'Product Naam' toe te voegen, <a href='inventory_list.php'>klik hier</a>";
exit();
}
// Add product to database
$sql = "INSERT INTO producten (product_naam,details,prijs,date_added) VALUES ('$product_naam','$details','$prijs',now())" or die (mysql_error());
$result=mysqli_query($con,$sql);
$pid = mysqli_insert_id($con);
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'],"../images/$newname");
header("location: inventory_list.php");
exit();
}
?>
<?php // This block grabs the whole list for viewing
$product_list="";
$sql = "SELECT * FROM producten";
$result = mysqli_query($con,$sql);
$productCount = mysqli_num_rows($result);
if ($productCount>0){
while($row=mysqli_fetch_array($result)){
$id=$row["id"];
$product_naam=$row["product_naam"];
$date_added = strftime("%b %d %Y", strtotime($row["date_added"]));
$product_list.="$date_added-$id-$product_naam <a href='inventory_edit.php?pid=$id'>Bewerken<a/> • <a href='#'>Verwijderen</a><br/>";
}
}else{
$product_list="Er zijn geen producten in de winkel!!";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Voorraadlijst</title>
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen">
</head>
<body>
<div id="mainWrapper" class="col-m-12 col-12"></div>
<?php include_once("../template_header.html");?>
<div id="pageContent">
<div align="right"><a href="inventory_list.php#inventoryForm">+ Voeg nieuw product toe</a></div>
<div align="left">
<h2>Voorraadlijst</h2>
<?php echo $product_list;?>
</div>
<a name="inventoryForm" id="inventoryForm"></a>
<h3>↓ Voeg een nieuw product toe ↓</h3>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"enctype="multipart/form-data" name="newprodForm" id="newprodForm" method="post">
<table class="col-m-11 col-11" border="0" cellspacing="0" cellpadding="6">
<tr>
<td class="col-m-2 col-2">Productnaam</td>
<td class="col-m-6 col-6"><label><input name="product_naam" type="text" id="product_naam" size="64"/></label></td></tr>
<tr><td class="col-m-2 col-2">Beschrijving</td><td class="col-m-6 col-6"><label><textarea name="details" type="textarea" id="details" cols="49" rows="5"/></textarea></label></td></tr>
<tr><td class="col-m-2 col-2">Prijs</td><td class="col-m-6 col-6"><label><input name="prijs" type="text" id="prijs"/></label></td></tr>
<tr><td class="col-m-2 col-2">Afbeelding</td><td class="col-m-6 col-6"><label><input type="file" name="fileField" id="fileField"/></label></td></tr>
<td><label><input type="submit" name="voegToe" id="voegToe" value="Product toevoegen"/></label></td></tr>
</table></form><br/><br/>
</div>
<?php include_once("../template_footer.html");?>
</div>
</body>
</html>