<?php
include 'include/AnonymousHeader.php';
$CON = @mysqli_connect('localhost', 'root', '', 'allyouneed') OR die('Could not connect to MySQL: ' . mysqli_connect_error());
?>
<table width="700">
<tr>
<td>
<h1>Sales Registration</h1>
</td>
</tr>
<?php
if (!(empty($_SESSION['LoginStatus']))) {
$SQL1 = "SELECT *
FROM sales";
$STM1 = @mysqli_query($CON, $SQL1);
$ROW = 0;
$SalesID = "";
if ($STM1) {
$ROW = @mysqli_num_rows($STM1);
} else {
echo mysqli_error($CON);
}
if ($ROW == 0) {
$SalesID = "SALES00001";
} else {
$SalesID = sprintf("SALES%05d", $ROW + 1);
}
if (isset($_POST['SUBMIT'])) {
$SalesProdName = $_POST['SalesProdName'];
$SalesDescription = $_POST['SalesDescription'];
$SalesImage = $_FILES['SalesImage'];
$SalesQty = $_POST['SalesQty'];
$SalesPrice = $_POST['SalesPrice'];
$SalesCategory = $_POST['SalesCategory'];
$MID = $_SESSION['IDInfo'];
$error = array();
if (!empty($SalesProdName)) {
if (!(preg_match('/^[A-Za-z0-9]+$/', $SalesProdName))) {
$error[] = 'Sales Name must only contains charater(s) or digit(s)';
}
} else {
$error[] = 'Sales Name must not be empty.';
}
if (empty($SalesDescription)) {
$error[] = 'Sales Description must not be empty.';
}
if ($SalesImage['size'] == 0) {
$error[] = 'No image was selected';
} else if ($SalesImage['error'] > 0) {
switch ($SalesImage['error']) {
case UPLOAD_ERR_NO_FILE:
$error[] = 'The file is not exist.';
break;
case UPLOAD_ERR_FORM_SIZE:
$error[] = 'image uploaded is too large. Maximum 1MB allowed.';
break;
default:
$error[] = 'There was an error while uploading the image.';
break;
}
} else if ($SalesImage['size'] > 1048576) {
$error[] = 'image uploaded is too large. Maximum 1MB allowed.';
} else {
$ext = strtolower(pathinfo($SalesImage['name'], PATHINFO_EXTENSION));
if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
$error[] = 'Only JPG, GIF and PNG format are allowed.';
}
}
if (!empty($error)) {
?>
<table border="1" bordercolor="red" bgcolor="pink" width="700">
<tr>
<td>
<h3>There are error(s) occured at the following area:</h3>
<?php
foreach ($error as $ERR) {
?>
<font color="red">=> <?php printf("%s", $ERR); ?></font><br/>
<?php
}
?>
</td>
</tr>
</table>
<?php
} else {
$save_as = $SalesID . '.' . $ext;
move_uploaded_file($SalesImage['tmp_name'], 'image/' . $save_as);
$SalesImage = 'image/' . $save_as;
$SalesStatus = "Available";
date_default_timezone_set("Asia/Kuala_Lumpur");
$CurrentDate = date('Ymd');
$CurrentDate = substr($CurrentDate, 0, 4) . '-' . substr($CurrentDate, 4, 2) . '-' . substr($CurrentDate, 6, 2);
$SQLSAL2 = "INSERT INTO sales
(SalesID, SalesProdName, SalesCategory, SalesImage, SalesDescription, SalesQty, SalesPrice, SalesStatus, MID, SalesDate)
VALUES('$SalesID', '$SalesProdName', '$SalesCategory', '$SalesImage' , '$SalesDescription', '$SalesQty', '$SalesPrice', '$SalesStatus', '$MID', '$CurrentDate')";
$SAL2 = @mysqli_query($CON, $SQLSAL2);
if ($SAL2) {
?>
<script language="javascript">alert("Sales Registered.")</script>
<?php
} else {
echo mysqli_error($CON);
}
}
}
}
?>
<form action="" method="POST" ENCTYPE = "multipart/form-data">
<table>
<tr>
<td>
Sales ID:
</td>
<td>
<?php echo "$SalesID"; ?>
</td>
</tr>
<tr>
<td>
Product Name :
</td>
<td>
<input type="text" name="SalesProdName" id="SalesProdName" maxlength="50"/>
</td>
</tr>
<tr>
<td>
Category :
</td>
<td>
<select name="SalesCategory" id="SalesCategory">
<option>Select one</option>
<option>Art</option>
<option>Book</option>
<option>Digital Device</option>
<option>Electronic</option>
<option>Entertainment</option>
<option>Model Figure</option>
<option>Sports</option>
<option>Vehicles</option>
<option>Video Games</option>
<option>Others</option>
</select>
</td>
</tr>
<tr>
<td>
Product Image :
</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<input type="file" name="SalesImage" id="SalesImage"/>
</td>
</tr>
<tr>
<td>
Product Description :
</td>
<td>
<textarea rows="3" cols="50" name="SalesDescription" id="SalesDescription"></textarea>
</td>
</tr>
<tr>
<td>
Quantity :
</td>
<td>
<input type="text" name="SalesQty" id="SalesQty">
</td>
</tr>
<tr>
<td>
Product Price :
</td>
<td>
<input type="text" name="SalesPrice" id="SalesPrice"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Submit" name="SUBMIT" ID="SUBMIT" />
<input type="reset" value="Reset" />
</td>
</tr>
</table>
</form>
<?php
include 'include/footer.php'
?>
aldred 0 Newbie Poster
coreyavis 13 Dev Poster
LastMitch
aldred 0 Newbie Poster
aldred 0 Newbie Poster
simplypixie 123 Posting Pro in Training
aldred 0 Newbie Poster
simplypixie 123 Posting Pro in Training
aldred 0 Newbie Poster
febinameer 0 Newbie Poster
simplypixie 123 Posting Pro in Training
aldred 0 Newbie Poster
aldred 0 Newbie Poster
simplypixie 123 Posting Pro in Training
aldred 0 Newbie Poster
coreyavis 13 Dev Poster
aldred 0 Newbie Poster
LastMitch
veedeoo 474 Junior Poster Featured Poster
aldred 0 Newbie Poster
LastMitch
PrimePackster commented: To Rectify what some retard did to LastMitch +0
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.