-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Product to the database except product image
- Loading branch information
Big Bug
committed
Feb 16, 2019
1 parent
ac14c18
commit 8867f6b
Showing
8 changed files
with
251 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
|
||
<?php | ||
session_start(); | ||
if ($_POST) { | ||
$name = $_POST['name']; | ||
$price = $_POST['price']; | ||
$details = $_POST['details']; | ||
|
||
print_r($_FILES['image']); | ||
exit; | ||
|
||
if (empty($name)) { | ||
$_SESSION['msg'] = "Please enter a Unique product name"; | ||
}else if(empty($price) || !is_numeric($price)){ | ||
$_SESSION['msg'] = "Please enter numeric price of the product"; | ||
}else if(empty($details)){ | ||
$_SESSION['msg'] = "Please enter product details"; | ||
}else if( strlen($details) > 300){ | ||
$_SESSION['msg'] = "Please enter product details in 300 words"; | ||
}else{ | ||
|
||
$_SESSION['msg']=""; | ||
$target_dir = "img/"; | ||
$target_file = $target_dir . basename($_FILES["image"]["name"]); | ||
$uploadOk = 1; | ||
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); | ||
// Check if image file is a actual image or fake image | ||
// if(isset($_POST["submit"])) { | ||
// $check = getimagesize($_FILES["image"]["tmp_name"]); | ||
// if($check !== false) { | ||
// $_SESSION['msg'] .= "File is an image - " . $check["mime"] . "."; | ||
// $uploadOk = 1; | ||
// } else { | ||
// $_SESSION['msg'] .= "File is not an image."; | ||
// $uploadOk = 0; | ||
// } | ||
// } | ||
// Check if file already exists | ||
if (file_exists($target_file)) { | ||
$_SESSION['msg'] .= "Sorry, file already exists."; | ||
$uploadOk = 0; | ||
} | ||
// Check file size | ||
if ($_FILES["image"]["size"] > 3000000) { | ||
$_SESSION['msg'] .= "Sorry, your file is too large."; | ||
$uploadOk = 0; | ||
} | ||
// Allow certain file formats | ||
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") { | ||
$_SESSION['msg'] .= "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; | ||
$uploadOk = 0; | ||
} | ||
// Check if $uploadOk is set to 0 by an error | ||
if ($uploadOk == 0) { | ||
$_SESSION['msg'] .= "Sorry, your file was not uploaded."; | ||
// if everything is ok, try to upload file | ||
} else { | ||
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { | ||
$_SESSION['msg'] .= "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; | ||
|
||
include_once "DB/DB_Connection.php"; | ||
$conn = DataBaseConnection(); | ||
$sql = "CREATE TABLE products( | ||
Id INT(5) PRIMARY KEY AUTO_INCREMENT, | ||
name VARCHAR(50), | ||
price INT(10), | ||
details VARCHAR(300), | ||
Image VARCHAR(30) | ||
)"; | ||
$conn->query($sql); | ||
|
||
$sql = "SELECT * FROM products WHERE name = '$name'"; | ||
$result = $conn->query($sql); | ||
if ($result->num_rows > 0) { | ||
$_SESSION['msg'] .= "This product already registared"; | ||
}else{ | ||
$sql = "INSERT INTO products(name,price,details,Image) VALUES ('$name',$price,'$details','$target_file')"; | ||
if($conn->query($sql)){ | ||
$_SESSION['msg'] .= "Product is registared into the system"; | ||
}else{ | ||
$_SESSION['msg'] .= "Product registration failed ".$conn->error; | ||
} | ||
} | ||
} else { | ||
$_SESSION['msg'] .= "Sorry, there was an error uploading your file."; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
header("location:../productRegistration.php"); | ||
} | ||
|
||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
|
||
|
||
|
||
<!-- head --> | ||
<?php include_once"templating/head.php" ?> | ||
|
||
<?php if (!isset($_SESSION['loggedIn'])){ | ||
header("location:login.php"); | ||
exit; | ||
} | ||
?> | ||
|
||
<!-- Navigation --> | ||
<?php include_once"templating/main_nav.php" ?> | ||
|
||
|
||
<!-- Page Content --> | ||
<div class="container"> | ||
|
||
<div class="row justify-content-center"> | ||
|
||
<div class="col-lg-6 bg-dark text-light mt-5 pb-5 pt-5"> | ||
|
||
<form action="php/productRegistrationCode.php" method="post" enctype="multipart/form-data"> | ||
<legend class="text-center text-uppercase">Product Registration</legend> | ||
<div class="form-group"> | ||
<label for="name">Product Name :</label> | ||
<input type="text" name="name" id="name" class="form-control" placeholder="Example: John Doe" value=''> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="price">Product Price :</label> | ||
<input type="price" name="price" id="price" class="form-control" placeholder="Example: [email protected]"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="details">Product Details :</label> | ||
<textarea name="details" id="details" class="form-control" placeholder="Product Details ( In 300 words )"></textarea> | ||
</div> | ||
<div class="form-group"> | ||
<label for="details">Product image :</label><br> | ||
<input type="file" name="image"> | ||
</div> | ||
<div class="form-group"> | ||
<input type="submit" class="form-control btn btn-success mt-4" value="SUBMIT"> | ||
</div> | ||
<p class="h4 text-center"><?php if (isset($_SESSION['msg'])) { | ||
echo($_SESSION['msg']); | ||
unset($_SESSION['msg']); | ||
} ?></p> | ||
</form> | ||
|
||
</div> | ||
|
||
</div> | ||
<!-- /.row --> | ||
<div class="col-lg-12 mt-5 mb-5"> | ||
<p class="h1 text-center">Product List</p> | ||
<table> | ||
<tr> | ||
<th class="text-center">Product Name</th> | ||
<th class="text-center">Price</th> | ||
<th class="text-center">Details</th> | ||
<th class="text-center">Action</th> | ||
<!-- <th></th> --> | ||
</tr> | ||
|
||
<?Php | ||
include_once "php/DB/DB_Connection.php"; | ||
$conn = DataBaseConnection(); | ||
$sql = "SELECT * FROM products"; | ||
$result = $conn->query($sql); | ||
foreach($result AS $row){ | ||
?> | ||
|
||
<tr> | ||
<td><?=$row['name']?></td> | ||
<td>$ <?=$row['price']?></td> | ||
<td><?=$row['details']?></td> | ||
<!-- <td>< ?=$row['image']?></td> --> | ||
<td class="d-flex justify-content-between"> | ||
<a class="btn btn-primary text-light" href="#"> EDIT </a> | ||
<a class="btn btn-danger text-light" href="#"> DELETE </a> | ||
</td> | ||
</tr> | ||
<?php } ?> | ||
|
||
</table> | ||
</div> | ||
</div> | ||
<!-- /.container --> | ||
|
||
<!-- Footer --> | ||
<?php include_once"templating/footer_area.php" ?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.