0% found this document useful (0 votes)
28 views

PHP Mysql

This document provides an overview of how to build a basic PHP and MySQL application for inserting, viewing, editing, and deleting data from a database table. It includes steps for creating a database and table, connecting a PHP file to the database, building PHP files for adding, viewing, editing and deleting records, and includes code examples for each file. The objective is to demonstrate basic CRUD operations using PHP and MySQL.

Uploaded by

Atiqur Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

PHP Mysql

This document provides an overview of how to build a basic PHP and MySQL application for inserting, viewing, editing, and deleting data from a database table. It includes steps for creating a database and table, connecting a PHP file to the database, building PHP files for adding, viewing, editing and deleting records, and includes code examples for each file. The objective is to demonstrate basic CRUD operations using PHP and MySQL.

Uploaded by

Atiqur Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Presentation Of

PHP MYSQL

Presented by
Md Atiqur Rahman (Polash)
Chief Technical Officer(CTO)
Doel e-Services
Web: doelhosting.com
Email: [email protected]
Mobile:01720981682
7/30/23 Web Design and Development 1
Today’s Objective
• Data Insert
• Data View
• Data Edit
• Data Delete

7/30/23 Web Design and Development 2


Mysql Database
• Create database Go : localhost/phpmyadmin/
• Database name : napd_test
• Create table: napd_about
• Colum name: id INT(10) auto increment
primary key, title(type text),detail(type
multitext),image(type text),date(type text)

7/30/23 Web Design and Development 3


PHP
• Create a new folder inside xampp->htdocs
• Folder name napd test
• Create folder name image inside napd test
where store in image

7/30/23 Web Design and Development 4


PHP Mysql Connect
• Create new php file using text editor
• Save the file inside napd test folder using name connect.php
• and insert the file bellow:
<?php
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'napd_test';
//connect with the database
$db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
mysqli_set_charset($db,"utf8");
?>

7/30/23 Web Design and Development 5


php file Name ‘add_about_us.php’
<?php include('connect.php'); ?>

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add About Us</title>
</head>

<body style="width:600px; margin:0 auto; padding:0; ">

<form action="add_about_us.php" method="post" style="margin-left:100px;" enctype="multipart/form-data"


>
<p style="font-size:36px; color:#03F;">Insert Into Napd About Us</p>
<table>
<tr>
<td>Title</td>
<td><input type="text" name="title" style="width:180px;" /></td>
</tr>

7/30/23 Web Design and Development 6


<tr>
<td>Detail</td>
<td><textarea name="detail" rows="10"></textarea></td>
</tr>
<tr>
<td>Image</td>
<td><input type="file" name="image" /></td>
</tr>
<tr>
<td></td>
<td> <br /><button type="submit" name="submit" >Submit</button></td>
</tr>
</table>

</form>

7/30/23 Web Design and Development 7


<?php

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

$current_date=date('F d,Y');
$title=$_POST['title'];
$detail=$_POST['detail'];
$post_file= $_FILES['image']['name'];
$file_tmp= $_FILES['image']['tmp_name'];
move_uploaded_file($file_tmp,"image/$post_file");
$q ="INSERT INTO `napd_about`(`title`, `detail`,`image`,`date`) VALUES ('$title','$detail','$post_file','$current_date')";
mysqli_query($db, $q);
if($q !=''){
echo "<script>alert('your information update successfuly')</script>";
echo "<script>window.open('add_about_us.php','_self')</script>";
}
}
?>
</body>
</html>

7/30/23 Web Design and Development 8


view_about_us.php
<?php include('connect.php'); ?>
<!DOCTYPE html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add About Us</title>
</head>
<body style="width:600px; margin:0 auto; padding:0; ">
<p style="font-size:36px; color:#03F; text-align: center;">View NAPD About Us</p>
<table style="width:600px" border="1">
<tr>
<th>SL</th>
<th>Title</th>
<th>Detail</th>
<th>Image</th>
<th>Option</th>
</tr>

7/30/23 Web Design and Development 9


<?php
$select_code = "SELECT * FROM `napd_about`";
$run_posts =mysqli_query($db, $select_code);
$i=1;
while($row= mysqli_fetch_array($run_posts))
{
$id=$row['id'];
$title=$row['title'];
$detail=$row['detail'];
$image=$row['image'];
$sl=$i++;
?>
<tr>
<td><?php echo $sl; ?></td>
<td><?php echo $title; ?></td>
<td><?php echo $detail; ?></td>
<td><img src="image/<?php echo $image; ?>" style="height:100px; width:100px;"/></td>
<td><a href="edit.php?id=<?php echo $id; ?>" style="text-decoration:none; border:1px solid #00F;">Update</a>&nbsp;&nbsp;<a
href="delete.php?id=<?php echo $id; ?>" style="text-decoration:none; border:1px solid #0F0;">Delete</a></td>
</tr>
<?php } ?>
</table>

</body>
</html>

7/30/23 Web Design and Development 10


<?php
include("connect.php");
edit.php
if(isset($_GET['id'])){
$edit_id = $_GET['id'];
}
$select_code = "SELECT * FROM `napd_about` where id='$edit_id'";
$run_posts = mysqli_query($db, $select_code);
$i=1;
while($row= mysqli_fetch_array($run_posts))
{
$id=$row['id'];
$title=$row['title'];
$detail=$row['detail'];
$image=$row['image'];
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update About Us</title>
</head>

7/30/23 Web Design and Development 11


<body style="width:600px; margin:0 auto; padding:0; ">

<form action="edit.php?id=<?php echo $edit_id; ?>" method="post" style="margin-left:100px;“ enctype="multipart/form-data" >


<p style="font-size:36px; color:#03F;">Insert Into Napd About Us</p>
<table>
<tr>
<td>Title</td>
<td><input type="text" name="title" style="width:180px;" value="<?php echo $title; ?>" /></td>
</tr>php

<tr>
<td>Detail</td>
<td><textarea name="detail" rows="10"><?php echo $detail; ?></textarea></td>
</tr>
<tr>
<td>Image</td>
<td><input type="file" name="image" /></td>
<td><img src="image/<?php echo $image; ?>" style="height:100px; width:100px;"/></td>
</tr>
<tr>
<td></td>
<td> <br /><button type="submit" name="submit">Update</button></td>
</tr>
</table>

</form>

7/30/23 Web Design and Development 12


<?php

if(isset($_POST['submit']))
{
$edit_id = $_GET['id'];
$current_date=date('F d,Y');
$title=$_POST['title'];
$detail=$_POST['detail'];
$post_file= $_FILES['image']['name'];
$file_tmp= $_FILES['image']['tmp_name'];
if($post_file==''){
$q ="UPDATE `napd_about` SET `title`='$title',`detail`='$detail' WHERE id='$edit_id'";
mysqli_query($db, $q);
}else{
move_uploaded_file($file_tmp,"image/$post_file");
$q ="UPDATE `napd_about` SET `title`='$title',`detail`='$detail',`image`='$post_file' WHERE
id='$edit_id'";
mysqli_query($db, $q);
}

echo "<script>alert('your information update successfuly')</script>";


echo "<script>window.open('view_about_us.php','_self')</script>";
}
?>
</body>
</html>
7/30/23 Web Design and Development 13
delete.php
<?php
include("connect.php");

if(isset($_GET['id'])){

$delete_id = $_GET['id'];

$delete="delete from `napd_about` where id='$delete_id'";


mysqli_query($db,$delete)

echo "<script>window.open('view_about_us.php','_self')</script>";
}
?>

7/30/23 Web Design and Development 14


• Any Question

7/30/23 Web Design and Development 15

You might also like