0% found this document useful (0 votes)
10 views3 pages

Admin Page

Uploaded by

Sajid Mahmud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Admin Page

Uploaded by

Sajid Mahmud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?

php

@include 'config.php';

if(isset($_POST['add_product'])){

$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp_name = $_FILES['product_image']['tmp_name'];
$product_image_folder = 'uploaded_img/'.$product_image;

if(empty($product_name) || empty($product_price) || empty($product_image)){


$message[] = 'please fill out all';
}else{
$insert = "INSERT INTO products(name, price, image) VALUES('$product_name',
'$product_price', '$product_image')";
$upload = mysqli_query($conn,$insert);
if($upload){
move_uploaded_file($product_image_tmp_name, $product_image_folder);
$message[] = 'new product added successfully';
}else{
$message[] = 'could not add the product';
}
}

};

if(isset($_GET['delete'])){
$id = $_GET['delete'];
mysqli_query($conn, "DELETE FROM products WHERE id = $id");
header('location:admin_page.php');
};

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>admin page</title>

<!-- font awesome cdn link -->


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/5.15.4/css/all.min.css">

<!-- custom css file link -->


<link rel="stylesheet" href="css/style.css">

</head>
<body>

<?php

if(isset($message)){
foreach($message as $message){
echo '<span class="message">'.$message.'</span>';
}
}

?>

<div class="container">

<div class="admin-product-form-container">

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"


enctype="multipart/form-data">
<h3>add a new product</h3>
<input type="text" placeholder="enter product name" name="product_name"
class="box">
<input type="number" placeholder="enter product price"
name="product_price" class="box">
<input type="file" accept="image/png, image/jpeg, image/jpg"
name="product_image" class="box">
<input type="submit" class="btn" name="add_product" value="add product">
</form>

</div>

<?php

$select = mysqli_query($conn, "SELECT * FROM products");

?>
<div class="product-display">
<table class="product-display-table">
<thead>
<tr>
<th>product image</th>
<th>product name</th>
<th>product price</th>
<th>action</th>
</tr>
</thead>
<?php while($row = mysqli_fetch_assoc($select)){ ?>
<tr>
<td><img src="uploaded_img/<?php echo $row['image']; ?>" height="100"
alt=""></td>
<td><?php echo $row['name']; ?></td>
<td>$<?php echo $row['price']; ?>/-</td>
<td>
<a href="admin_update.php?edit=<?php echo $row['id']; ?>"
class="btn"> <i class="fas fa-edit"></i> edit </a>
<a href="admin_page.php?delete=<?php echo $row['id']; ?>"
class="btn"> <i class="fas fa-trash"></i> delete </a>
</td>
</tr>
<?php } ?>
</table>
</div>

</div>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy