Kód: Vybrať všetko
<?php
require("../db.php");
if($_POST['submit'])
{
if (
empty($_POST['name']) ||
empty($_POST['description']) ||
empty($_POST['long_description']) ||
empty($_POST['price']))
{
?>
<script language="javascript">
alert("Enter all the information about product!!!.");
</script>
<meta http-equiv="refresh" content="0; url=addproduct.php">
<?php
die();
}
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if (file_exists("../productimages/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../productimages/" . $_FILES["file"]["name"]);
}
}
else
{
?>
<script language="javascript">
alert("Picture must be jpg/gif and small as 2mb.");
</script>
<meta http-equiv="refresh" content="0; url=addproduct.php">
<?php
die();
}
$addsql = "INSERT INTO
products (cat_id, name, description,
long_description, image, price, date)
VALUES('".$_POST['amountBox']."',
'".$_POST['name']."',
'".$_POST['description']."',
'".$_POST['long_description']."',
'".$_FILES['file']['name']."',
'".$_POST['price']."'
NOW())";
mysql_query($addsql);
echo "This product was added !";
}
else
{
require("header_admin.php");
$sql = 'SELECT * FROM categories';
$getUser = mysql_query($sql);
echo "<form action='" . $SCRIPT_NAME . "' method='POST' enctype='multipart/form-data'>";
?>
<h1>Add product</h1>
<table>
<tr>
<td>Name</td>
<td><input type="text" name="name" size="30"></td>
</tr>
<tr>
<td>Category</td>
<td><select name='amountBox'>";
<?php while ($row = mysql_fetch_array($getUser)) {?>
<option value="<?php echo $row['id']; ?>">
<?php echo $row['name']; ?></option>
<?php } ?>
</td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="description" size="40"></td>
</tr>
<tr>
<td>Long Description</td>
<td WIDTH="400px"><textarea name="long_description" class="widgEditor nothing"></textarea></td>
</tr>
<tr>
<td>Price</td>
<td>£<input type="text" name="price"></td>
</tr>
<tr>
<td>Image</td>
<td><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" ></td>
</tr>
</table>
</form>
<?php
}
require("footer_admin.php");
?>