PHP coding (please use mysqli instead of mysql)
Create an Admin Control Panel page for your shop. Your admin page can perform the following tasks:
Challenge:
Databasse.php
<?php
class database{
private $_host = 'localhost';
private $_username = 'root';
private $_password = '';
private $_database = 'tableproduct';
public $conn;
function __construct()
{
if (!isset($this->conn)) {
$this->conn = new mysqli($this->_host, $this->_username,
$this->_password, $this->_database);
if (!$this->conn) {
echo 'Cannot connect to database server';
exit;
}
}
return $this->conn;
}
function insert($table_name, $data)
{
$string = "INSERT INTO ".$table_name." (";$string .= implode(",",
array_keys($data)) . ') VALUES (';
$string .= "'" . implode("','", array_values($data)) . "')";
print_r($string);
if(mysqli_query($this->conn, $string))
{
return true;
}
else
{
echo mysqli_error($this->conn);
}
}
function select($f,$table_name,$wh ='',$ob='')
{
$array = array();
$ValueToSearch = '';
$query = "SELECT * FROM ".$table_name." WHERE 1 " .$wh .($ob ? '
ORDER BY ' .$ob :' ' );
$result = mysqli_query($this->conn, $query);
while($row = mysqli_fetch_assoc($result))
{
$array[] = $row;
}
return $array;
}
function select_where($table_name, $where_condition)
{
$condition = '';
$array = array();
foreach($where_condition as $key => $value)
{
$condition .= $key . " = '".$value."' AND ";
}
$condition = substr($condition, 0, -5);
$query = "SELECT * FROM ".$table_name." WHERE " . $condition;
$result = mysqli_query($this->conn, $query);
while($row = mysqli_fetch_array($result))
{
$array[] = $row;
}
return $array;
}
function update($table_name, $fields, $where_condition)
{
$query = '';
$condition = '';
foreach($fields as $key => $value)
{
$query .= $key . "='".$value."', ";
}
$query = substr($query, 0, -2);
/*This code will convert array to string like this-
input - array(
'key1' => 'value1',
'key2' => 'value2'
)
output = key1 = 'value1', key2 = 'value2'*/
foreach($where_condition as $key => $value)
{
$condition .= $key . "='".$value."' AND ";
}
$condition = substr($condition, 0, -5);
$query = "UPDATE ".$table_name." SET ".$query." WHERE
".$condition."";
if(mysqli_query($this->conn, $query))
{
return true;
}
}
function delete($table_name, $where_condition)
{
$condition = '';
foreach($where_condition as $key => $value)
{
$condition .= $key . " = '".$value."' AND ";
$condition = substr($condition, 0, -5);
$query = "DELETE FROM ".$table_name." WHERE
".$condition."";
if(mysqli_query($this->conn, $query))
{
return true;
}
}
}
}
?>
################
product.php
<?php
include("database.php");
$db=new database();
if(isset($_POST['submit'])){
$imagetype=$_FILES["image"]['type'];
$imagesize=$_FILES["image"]['size'];
$image_Arr = $_FILES['image'];
$temp = $_FILES["image"]["name"];
// allowed
extensions
$extension = explode(".", $temp);
$allowed_extensions =
array("jpg","jpeg","png","gif");
if(!in_array($extension[1],$allowed_extensions))
{
echo "<script>alert('Invalid format. Only
jpg / jpeg/ png /gif format allowed');</script>";
}
else{
move_uploaded_file($_FILES["image"]["tmp_name"],
"./uploads/" . $temp);
$insert_data=array(
'image' =>
mysqli_real_escape_string($db->conn,
$_FILES['image']['name']),
'pro_name' =>
mysqli_real_escape_string($db->conn, $_POST['pro_name']),
'pro_code' =>
mysqli_real_escape_string($db->conn, $_POST['pro_code']),
'price' =>
mysqli_real_escape_string($db->conn, $_POST['price']),
'quantity' =>
mysqli_real_escape_string($db->conn,
$_POST['quantity']),
'contact' =>
mysqli_real_escape_string($db->conn, $_POST['contact']),
);
$pro_code =
$_POST['pro_code'];
$query= "SELECT * FROM product
WHERE pro_code='$pro_code'";
$result=
mysqli_query($db->conn,$query);
$sql =
mysqli_num_rows($result);
if($sql>0)
{
echo "Sorry, Productcode must be
unique.";
return false; }
else {
$db->insert('product',
$insert_data);
header("location:dis_product.php");
}
}
}
?>
<html>
<body>
<form enctype="multipart/form-data" action="product.php" method="POST" name="myForm" onsubmit="return validateForm()">
<h2>Product</h2>
Image:
<input type="file"
class="upload_file" name="image" id="image"
multiple="multiple"></input><br /><br/>
Product_Name:
<input type="text"
name="pro_name" id="pro_name"><br><br>
Product_Code:
<input type="text" name="pro_code"
id="pro_code"><br><br>
Price:
<input type="text" name="price"
id="price"><br><br>
Quantity:
<input type="text"
name="quantity" id="quantity"
maxlength="10"><br><br>
<input type="submit" name="submit" value="submit
form"><br><br>
<a
href="dis_product.php">Display</a>
</form>
</body>
</html>
######################
edit_product.php
<?php
include("database.php");
$edit=new database();
if(isset($_POST['edit'])){
$image=$_FILES['image']['name'];
$imgfile=$_FILES["image"]["name"];
// get the image extension
$extension = explode(".", $imgfile);
// allowed extensions
$allowed_extensions =
array("jpg","jpeg","png","gif");
if(!in_array($extension[1],$allowed_extensions))
{
echo "<script>alert('Invalid format. Only
jpg / jpeg/ png /gif format allowed');</script>";
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],"./uploads/".$imgfile);
$update_data = array(
'image' =>
mysqli_real_escape_string($edit->conn, $image),
'pro_name' =>
mysqli_real_escape_string($edit->conn,
$_POST['pro_name']),
'price' =>
mysqli_real_escape_string($edit->conn, $_POST['price']),
'quantity' =>
mysqli_real_escape_string($edit->conn,
$_POST['quantity']),
);
$where_condition = array(
'pro_id' =>
$_POST["pro_id"]
);
if($edit->update("product",
$update_data, $where_condition))
{
header("location:dis_product.php?updated=1");
}
}
}
?>
<html>
<body>
<form enctype="multipart/form-data" action="edit_product.php" method="POST">
<?php
if(isset($_GET["edit"]))
{
if(isset($_GET["pro_id"]))
{
$where = array(
'pro_id' => $_GET["pro_id"]
);
$single_data = $edit->select_where("product", $where);
foreach($single_data as $row)
{
?>
<h2>Product</h2>
<input type="hidden"
name="pro_id" value="<?php echo $row["pro_id"];?>">
Image:
<input type="file"
class="upload_file" name="image" value="<?php echo
$row["image"]; ?>"></input><br
/><br/>
Product_Name:
<input type="text"
name="pro_name" id="pro_name" value="<?php echo
$row["pro_name"]; ?>"><br><br>
Price:
<input type="text" name="price" id="price"
value="<?php echo $row["price"];
?>"><br><br>
Quantity:
<input type="text"
name="quantity" id="quantity" value="<?php echo
$row["quantity"]; ?>"><br><br>
<input type="submit" name="edit"
value="update"><br><br>
<a
href="dis_product.php">Display</a>
</form>
<?php
}
}
}
?>
</body>
</html>
################################
Delete Or Display
dis_product.php
<?php
include("database.php");
$fetchdata = new database();
if(isset($_GET['action']) and $_GET['action']=="delete")
{
$where = array(
'pro_id' => $_GET["pro_id"]
);
if($fetchdata->delete("product", $where))
{
header("location:dis_product.php?deleted=1");
}
}
?>
<html>
<body>
<table border='1'>
<tr>
<th>Image</th>
<th>Product_name</th>
<th>Product_code</th>
<th>Price</th>
<th>quantity</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>
<?php //code for read data from Database
$i=1;
$wh = '';
$fetch_data =$fetchdata->select('$f','product',$wh,'');
foreach($fetch_data as $post)
{
?>
<tr>
<td><img height="50" width="50" src="./uploads/<?php
echo $post['image']?> "></td>
<td> <?php echo $post["pro_name"];?></td>
<td> <?php echo $post["pro_code"];?></td>
<td> <?php echo $post["price"];?></td>
<td> <?php echo $post["quantity"];?></td>
<td><a href="edit_product.php?edit=1&pro_id=<?php
echo $post["pro_id"]; ?>">Edit</a></td>
<td><a href="dis_product.php?pro_id=<?php echo $post['pro_id']; ?>&action=delete" onclick="return confirm('Confirm to delete ??');">Delete</a></td>
</tr>
<?php
}
?>
</table>
<a href="product.php" >Add
Product</a><br><br>
<a href="logout.php">Logout</a>
</body>
</html>
#########################3
Please find Below Attachment:: https://nimb.ws/x1AaXd
PHP coding (please use mysqli instead of mysql) Create an Admin Control Panel page for your...
Create a Web page to be used for storing software development bug reports in a MySQL database. Include fields such as product name and version, type of hardware, operating system, frequency of occurrence, and proposed solutions. On the main page you display all the reported bugs (hint: use a table). Include a link at the bottom of the page which takes you to another page where you can create a new bug report. Furthermore, add a link after every filed...
Instructions Using Php and MySQL, database from Xampp In this assignment, you will create an application using PHP and MySQL, incorporating all of the skills that you have learned throughout the course. As you complete the project, be sure that you are using the correct format and syntax as well as the appropriate structure for your coding. To move forward to the next module, you will need to demonstrate mastery by scoring an 80% or higher. If you score less...
PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...
HTML / CSS
Content Requirements
Create a home page with the following elements and settings:
Set the background, font colors, and “theme” to match those used
in lab assignment #1 using an external css file; inline styling
should be used only where necessary to override styling from the
external css
H1 element, centered at the top of the page, with “Thank you for
choosing Your Company Name. . . “ text*
Div or other container with at least 5 sentences...
Project Description In this project, you will design and implement a database for keeping track of information for an online “SOCIAL NETWORK” system (e.g. a simplified version of Facebook!). You will first design an EER schema diagram for this database application. Then, you will map the EER schema into a relational database schema and implement it on ORACLE or MySQL or some other relational DBMS. Finally, you will load some data into your database (via user Interface) and create some...
Rationale The focus of the project is to develop your database programming skills. This project will help you get a fair idea of the sales and distribution system in any organization that has a chain of Carrying and Forwarding Agents (CFAs) or super stockists and stockists. You will be able to implement database programming concepts of ADO.NET in VB.NET and ASP.NET to create a real-life, web-based database application. (VB stands for Visual Basic.) Scenario Smooth Pen, Inc., a pen manufacturing...
For this course project, you will use various database management and programming techniques to design and develop an online sales and distribution system for a fictitious organization. There are two phases—you will complete the first phase this week and the second phase in W5 Assignment 2. Rationale The focus of the project is to develop your database programming skills. This project will help you get a fair idea of the sales and distribution system in any organization that has a...
You are the systems manager for Blue City Movies Rentals and you have been asked to create a report on historical sales data. To complete your task you will combine and edit data from multiple sources using Excel’s Power add-ins, XML, and text functions.Instructions:For the purpose of grading the project you are required to perform the following tasks:StepInstructionsPoints Possible1Open e10c2MovieRentals.xlsx and save the workbook with the name e10c2MovieRentals_LastFirst.02Import the movie data from the delimited file e10c2Movies.txt and rename the new worksheet Inventory.Hint: On the Data tab,...
I need help writting a Javascript function that does the
following its for a HTML/CSS Shopping Cart Page
CODE
This page contains a list of the selected products that includes an image, name, price, quantity, and cost) Because the process is implemented not as real, three products along with its image and price are displayed on the page. The product ID of each product is stored in a hidden textbox. The default amount of each product is 1 and the...
internal project 1
anything helps! thank you!!
Instructions: Study the case that starts on page 3 carefully. Then write concise answers to the following questions regarding the internal control system of Duarf, Inc. Clearly label your responses with proper headings and subheadings. Be very specific and precise. Answers that appear to be beating around the bush will not get any credit. 1. What are the controls in place that under normal conditions should function well to prevent embezzlements or frauds?...