Posted inProgramming / Mysql / Mysqli / php

PHP MySQLi CRUD Insert Update Delete

PHP MySQLi CRUD Insert Update Delete

Today, We want to share with you PHP MySQLi CRUD Insert Update Delete.
In this post we will show you PHP CRUD Operations with MySQLi Extension, hear for Multiple Insert, Update, Delete example using PHP & MySQLi we will give you demo and example for implement.
In this post, we will learn about Simple Add, Edit, Delete, View (CRUD) in PHP & MySQLi with an example.

Welcome to the In Pakainfo.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.

testdb.php – create Database / Table / insert records


--
-- Table structure for table `salestbl_users`
--

CREATE TABLE IF NOT EXISTS `salestbl_users` (
  `SalesuserID` int(11) NOT NULL AUTO_INCREMENT,
  `SalesuserName` varchar(20) NOT NULL,
  `SalespersonUser` varchar(50) NOT NULL,
  `salesuserimg` varchar(200) NOT NULL,
  PRIMARY KEY (`SalesuserID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ;

--
-- Dumping data for table `salestbl_users`
--

INSERT INTO `salestbl_users` (`SalesuserID`, `SalesuserName`, `SalespersonUser`, `salesuserimg`) VALUES
(78, 'dave chirag', 'actor, wrestler', '989855.jpg'),
(79, 'mayur dhameliya', 'singer', '98256.jpg'),
(80, 'hitesh savaliya', 'actor', '06214.jpg'),
(81, 'vishal pandya', 'wrestler', '90994.jpg');

dbconfig.php

$DB_HOST_DATA = 'localhost or ip address';
$DB_USER_DATA = 'root';
$DB_PASS_DATA = '4****125';
$DB_PASS_DATA = 'testdb';
	try{
		$Con_DB_PASS = new PDO("mysql:host={$DB_HOST_DATA};dbname={$DB_PASS_DATA}",$DB_USER_DATA,$DB_PASS_DATA);
		$Con_DB_PASS->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	}
	catch(PDOException $e){
		echo $e->getMessage();
	}

index.php

	require_once 'dbconfig.php';
	if(isset($_GET['user_delete_id']))
	{
		// select Picture or Picture or Image from db to delete
		$query_stmt_select_r = $Con_DB_PASS->prepare('SELECT salesuserimg FROM salestbl_users WHERE SalesuserID =:uid');
		$query_stmt_select_r->execute(array(':uid'=>$_GET['user_delete_id']));
		$picimgRowdata=$query_stmt_select_r->fetch(PDO::FETCH_ASSOC);
		unlink("user_Picture or Images/".$picimgRowdata['salesuserimg']);
		
		// it will delete record an actual record from db
		$sales_stmt_delete_r = $Con_DB_PASS->prepare('DELETE FROM salestbl_users WHERE SalesuserID =:uid');
		$sales_stmt_delete_r->bindParam(':uid',$_GET['user_delete_id']);
		$sales_stmt_delete_r->execute();
		//redirects url
		header("Location: index.php");
	}

[html]


Upload data, Insert data, Update data, Delete data an Picture or Picture or Image using PHP and MySQL – Coding script

prepare(‘SELECT SalesuserID, SalesuserName, SalespersonUser, salesuserimg FROM salestbl_users ORDER BY SalesuserID DESC’);
$stmt->execute();

if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>

Edit
Delete

  No Data Found …

tutorial link here ! Coding Cage!


<script>

[/html]

addnew.php

error_reporting( ~E_NOTICE ); // error avoid notice

require_once ‘dbconfig.php’;

if(isset($_POST[‘btnsave’]))
{
$SalesuserName = $_POST[‘sl_user_name’];// user name
$userjob = $_POST[‘title_user_job’];// user email

$imgFile = $_FILES[‘user_Picture or Image’][‘name’];
$tmp_dir = $_FILES[‘user_Picture or Image’][‘tmp_name’];
$totalimgSize = $_FILES[‘user_Picture or Image’][‘size’];

if(empty($SalesuserName)){
$Message_error = “Please Write your SalesuserName.”;
}
else if(empty($userjob)){
$Message_error = “Please Write your Your Job Work.”;
}
else if(empty($imgFile)){
$Message_error = “Please Select Picture or Image File.”;
}
else
{
$name_upload_dir_n = ‘user_Picture or Images/’; // upload directory

$imgExt_sto = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get Picture or Picture or Image extension

// valid Picture or Image extensions
$data_valid_extensions = array(‘jpeg’, ‘jpg’, ‘png’, ‘gif’); // valid extensions

// rename uploading Picture or Picture or Image
$salesuserimg = rand(1000,1000000).”.”.$imgExt_sto;

// allow valid Picture or Picture or Image file formats
if(in_array($imgExt_sto, $data_valid_extensions)){
// Check file size ‘5MB’
if($totalimgSize < 5000000) { move_uploaded_file($tmp_dir,$name_upload_dir_n.$salesuserimg); } else{ $Message_error = “Sorry, your file is too large.”; } } else{ $Message_error = “Sorry, only JPG, JPEG, PNG & GIF files are allowed.”; } } // if no error occured, continue …. if(!isset($Message_error)) { $stmt = $Con_DB_PASS->prepare(‘INSERT INTO salestbl_users(SalesuserName,SalespersonUser,salesuserimg) VALUES(:uname, :ujob, :upic)’);
$stmt->bindParam(‘:uname’,$SalesuserName);
$stmt->bindParam(‘:ujob’,$userjob);
$stmt->bindParam(‘:upic’,$salesuserimg);

if($stmt->execute())
{
$MessageSuccess_var = “new record succesfully inserted …”;
header(“refresh:5;index.php”); // redirects Picture or Picture or Image view page after 5 seconds.
}
else
{
$Message_error = “error while inserting….”;
}
}
}

[html]


Upload data,data Insert, data Update, data Delete an Picture or Picture or Image using PHP with MySQL – Coding script

Profession(Job). Profile Img.
tutorial link ! Coding Cage!


<script>


[/html]

editform.php


	error_reporting( ~E_NOTICE );
	
	require_once 'dbconfig.php';
	
	if(isset($_GET['data_edit_id_r']) && !empty($_GET['data_edit_id_r']))
	{
		$id = $_GET['data_edit_id_r'];
		$data_stmt_edit_res = $Con_DB_PASS->prepare('SELECT SalesuserName, SalespersonUser, salesuserimg FROM salestbl_users WHERE SalesuserID =:uid');
		$data_stmt_edit_res->execute(array(':uid'=>$id));
		$row_edit_result = $data_stmt_edit_res->fetch(PDO::FETCH_ASSOC);
		extract($row_edit_result);
	}
	else
	{
		header("Location: index.php");
	}
	
	
	
	if(isset($_POST['save_bttn_update_data']))
	{
		$SalesuserName = $_POST['sl_user_name'];// user name
		$userjob = $_POST['title_user_job'];// user email
			
		$imgFile = $_FILES['user_Picture or Image name']['name'];
		$tmp_dir = $_FILES['user_Picture or Image name']['tmp_name'];
		$totalimgSize = $_FILES['user_Picture or Image name']['size'];
					
		if($imgFile)
		{
			$name_upload_dir_n = 'user_Picture or Images/'; // upload directory	
			$imgExt_sto = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get Picture or Picture or Image extension
			$data_valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
			$salesuserimg = rand(1000,1000000).".".$imgExt_sto;
			if(in_array($imgExt_sto, $data_valid_extensions))
			{			
				if($totalimgSize < 5000000) { unlink($name_upload_dir_n.$row_edit_result['salesuserimg']); move_uploaded_file($tmp_dir,$name_upload_dir_n.$salesuserimg); } else { $Message_error = "Sorry, your file is too large it should be less then 5MB"; } } else { $Message_error = "Sorry, only JPG img, JPEG img, PNG img & GIF img files or images are allowed."; } } else { // if no Picture or Image selected the old Picture or Picture or Image remain as it is. $salesuserimg = $row_edit_result['salesuserimg']; // old Picture or Picture or Image from database } // if no error occured, continue .... if(!isset($Message_error)) { $stmt = $Con_DB_PASS->prepare('UPDATE salestbl_users 
									     SET SalesuserName=:uname, 
										     SalespersonUser=:ujob, 
										     salesuserimg=:upic 
								       WHERE SalesuserID=:uid');
			$stmt->bindParam(':uname',$SalesuserName);
			$stmt->bindParam(':ujob',$userjob);
			$stmt->bindParam(':upic',$salesuserimg);
			$stmt->bindParam(':uid',$id);
				
			if($stmt->execute()){
				?>
                PHP MySQLi CRUD Insert Update Delete
                

Insert,Update,Delete,Upload an Picture or Image using PHP with MySQL

[html]


Upload, Insert, Update, Delete an Picture or Image using PHP MySQL - Coding Cage
PHP MySQLi CRUD Insert Update Delete

<script>

 

cancel Record

tutorial link ! Coding Cage!



[/html]

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype