<?php
function createProduct($db)
{
if(isset($_POST['CreateProductSubmit']))
{
if(!empty($_POST['newBrand']))
$brandid = $_POST['newBrand'];
else
$brandid = $_POST['ProductBrand'];
var_dump($_POST);
if(required($brandid) && empty($_POST['image']) && required($_POST['productDesc']))
{
echo "<p style='color: red;'>Nogle felter mangler, venligst udfyld alle!</p>";
}
else
{
$path = '/lucas/images/products/';
$dbnewname = imageUpload(10000, 100, 100, '', 5, $path);
var_dump($brandid);
var_dump($dbnewname);
if(empty($dbnewname))
$dbnewname = $path . 'noimage.jpg';
}
}
?>
<form class="adminForm" enctype="multipart/form-data" action="" method="post">
<h2>Produkt navn</h2>
<input type="text" name="productName" />
<h2>Beskrivelse</h2>
<textarea name="productDesc"></textarea>
<h2>Mærke</h2>
<?php
$stmt = $db->prepare("SELECT `id`, `brand` FROM products GROUP BY `brand`;");
$stmt->execute();
echo "<select name='ProductBrand'>";
echo "<option value='0'>Vælg Mærke</option>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($brandid == $row['brand']) {
$selected = "selected='selected'";
} else if ($_POST['ProductBrand'] == 0) {
$selected = null;
}
else
$selected = null;
echo "<option $selected value='{$row['brand']}'>{$row['brand']}</option>";
$selected = null;
}
echo "</select>";
?>
eller <input type="text" name="newBrand" />
<h2>Billeder</h2>
<input type="file" name="image[]" />
<input type="submit" name="CreateProductSubmit" />
</form>
<?php
}
?>