Tagged: insert update delete in php with source code

PHP MySQLi Insert Update Delete Query Builder 0

PHP MySQLi Insert Update Delete Query Builder

Today, We want to share with you PHP MySQLi Insert Update Delete Query Builder.In this post we will show you INSERT, UPDATE and DELETE with mysqli, hear for PHP OOPs dynamic insert update delete data in MySQLi we will give you demo and example for implement.In this post, we will learn about Create a Simple CRUD Database App: Connecting to MySQLi with PHP with an example.

PHP MySQLi Insert Update Delete Query Builder

There are the Following The simple About PHP MySQLi Insert Update Delete Query Builder Full Information With Example and source code.

As I will cover this Post with live Working example to develop Update Data in MySQL Database Table Using PHP with MySQLi, so the php MySQLi code for updating data in mysql database for this example is following below.

Connect to Database

The PHP MySqli Simple two basic ways to connect to the database Like as a procedural and object oriented

$mysqli =  mysqli_connect('host','root','my_pwd','aisd');

$mysqli = new mysqli('host','root','my_pwd','aisd');

“object-oriented” Get Errors

<?php
$mysqli = new mysqli('host','your_uname','pwd','atmiya25');

if ($mysqli->connect_error) {
    die('Sorry, Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

?>

SELECT Multiple Records

PHP mysqli SELECT Multiple Records as Associative array

<?php
$mysqli = new mysqli('host','root-uname','db_pass','atmiya25');

if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table border="1">';
while($row = $results->fetch_assoc()) {
	print '<tr>';
    print '<td>'.$row["id"].'</td>';
	print '<td>'.$row["member_code"].'</td>';
	print '<td>'.$row["member_name"].'</td>';
	print '<td>'.$row["member_desc"].'</td>';
	print '<td>'.$row["reputations"].'</td>';
	print '</tr>';
}  
print '</table>';

$results->free();

$mysqli->close();
?>

PHP MySQLi SELECT Multiple Records as Array

fetch_array() : Function returns an array

<?php
$mysqli = new mysqli('host','root-uname','db_pass','atmiya25');

if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table border="1"';
while($row = $results->fetch_array()) {
	print '<tr>';
    print '<td>'.$row["id"].'</td>';
	print '<td>'.$row["member_code"].'</td>';
	print '<td>'.$row["member_name"].'</td>';
	print '<td>'.$row["member_desc"].'</td>';
	print '<td>'.$row["reputations"].'</td>';
	print '</tr>';

}   
print '</table>';
$results->free();

$mysqli->close();
?>

PHP MySQLi SELECT Multiple Records as Objects

<?php
$mysqli = new mysqli('host','root-uname','db_pass','atmiya25');

if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT id, member_code, member_desc, reputations FROM members");

print '<table border="1">';
while($row = $results->fetch_object()) {
	print '<tr>';
    print '<td>'.$row->id.'</td>';
	print '<td>'.$row->member_code.'</td>';
	print '<td>'.$row->member_name.'</td>';
	print '<td>'.$row->member_desc.'</td>';
	print '<td>'.$row->reputations.'</td>';
	print '</tr>';
}  

print '</table>';

$mysqli->close();
?>

SELECT Single value

<?php
$mysqli = new mysqli('host','root-uname','db_pass','atmiya25');

if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$member_name = $mysqli->query("SELECT member_name FROM members WHERE id = 1")->fetch_object()->member_name; 
print $member_name; //output value

$mysqli->close();
?>

PHP MySQLi SELECT COUNT Total records of a table

<?php
$mysqli = new mysqli('host','root-uname','db_pass','atmiya25');

if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT COUNT(*) FROM members");
$get_total_rows = $results->fetch_row(); //hold total records in variable

$mysqli->close();
?>

PHP MySQLi SELECT Using Prepared Statements

$search_member = "MD1001"; //member id

$query = "SELECT id, member_code, member_desc, reputations FROM members WHERE member_code=?";
$statement = $mysqli->prepare($query);

$statement->bind_param('s', $search_member);

$statement->execute();

$statement->bind_result($id, $member_code, $member_desc, $reputations);

print '<table border="1">';

while($statement->fetch()) {
	print '<tr>';
    print '<td>'.$id.'</td>';
	print '<td>'.$member_code.'</td>';
	print '<td>'.$member_desc.'</td>';
	print '<td>'.$reputations.'</td>';
	print '</tr>';

}   
print '</table>';

//close connection
$statement->close();

PHP MySQLi Insert or Update if record already exists

Simple Insert or Update if record already exists Query

$id = 0; 
$member_code = "M98256";
$member_name = "Krunal Sisodiya";
$member_desc = "Best friends To Parag shukla from DSP study Points";
$reputations = "1000";

$query = "INSERT INTO members (id, member_code, member_name, member_desc, reputations) 
			VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE member_code=?, member_name=?, member_desc=?, reputations=?";

$statement = $mysqli->prepare($query);

$statement->bind_param('dsssdsssd', $id, $member_code, $member_name, $member_desc, $reputations, //insert vars
									 $member_code, $member_name, $member_desc, $reputations); //update vars

$statement->execute();

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP MySQLi Insert Update Delete Query Builder.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP MySQLi CRUD Insert Update Delete 0

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>
<head>
<title>Upload data, Insert data, Update data, Delete data an Picture or Picture or Image using PHP and MySQL - Coding script</title>
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap.min.css">
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap-theme.min.css">
</head>
<body>
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
            <a class="navbar-brand" href="https://pakainfo.com/" title='Programming Blog'>Coding Cage</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/CRUD">CRUD</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/PDO">PDO</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/jQuery">jQuery</a>
        </div>
    </div>
</div>
<div class="container">
<div class="page-header">
<h1 class="h2">Data all members. / <a class="btn btn-default" href="addnew.php"> <span class="glyphicon glyphicon-plus"></span>   Create add new </a></h1>

    </div>
<div class="row">
<?php $stmt = $Con_DB_PASS->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);
			?>

<div class="col-xs-3">


<?php echo $SalesuserName." / ".$SalespersonUser; ?>

				<img src="user_Picture or Images/<?php echo $row['salesuserimg']; ?>" class="img-rounded" width="250px" height="250px" />


				<span>
				<a class="btn btn-info" href="editform.php?data_edit_id_r=<?php echo $row['SalesuserID']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a> 
				<a class="btn btn-danger" href="?user_delete_id=<?php echo $row['SalesuserID']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
				</span>
			</div>

			<?php } } else { ?>

<div class="col-xs-12">

<div class="alert alert-warning">
            	<span class="glyphicon glyphicon-info-sign"></span>   No Data Found ...
            </div>

        </div>

        <?php } ?>
</div>

	
<div class="alert alert-info">
    <strong>tutorial link here !</strong> <a href="https://pakainfo.com/2016/02/upload-insert-update-delete-Picture or Image-using.html">Coding Cage</a>!
</div>

</div>

<!-- New Latest compiled js and minified JavaScript(js) -->
<img src="data:image/gif;" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</body>
</html>

addnew.php

[/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….”;
}
}
}

[/php]

<html>
<head>
<title>Upload data,data Insert, data Update, data Delete an Picture or Picture or Image using PHP with MySQL - Coding script</title>
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap.min.css">
<!-- it is linking - Optional - data theme link -->
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap-theme.min.css">
</head>
<body>
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
            <a class="navbar-brand" href="https://pakainfo.com/" title='Programming Blog'>Coding Cage</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/CRUD">CRUD</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/PDO">PDO</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/jQuery">jQuery</a>
        </div>

 
    </div>

</div>
<div class="container">
<div class="page-header">
<h1 class="h2">add new user. <a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-eye-open"></span>   view all </a></h1>
    </div>
	<?php if(isset($Message_error)){ ?>

<div class="alert alert-danger">
            	<span class="glyphicon glyphicon-info-sign"></span> <strong><?php echo $Message_error; ?></strong>
            </div>

            <?php } else if(isset($MessageSuccess_var)){ ?>

<div class="alert alert-success">
              <strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $MessageSuccess_var; ?></strong>
        </div>

        <?php } ?>   

<form method="post" enctype="multipart/form-data" class="form-horizontal">
<table class="table table-bordered table-responsive">
<tr>

<td><label class="control-label">SalesuserName.</label></td>
<td><input class="form-control" type="text" name="sl_user_name" placeholder="Write your SalesuserName" value="<?php echo $SalesuserName; ?>" /></td>

    </tr>
<tr>
<td><label class="control-label">Profession(Job).</label></td>
<td><input class="form-control" type="text" name="title_user_job" placeholder="Your Profession" value="<?php echo $userjob; ?>" /></td>

    </tr>
<tr>
<td><label class="control-label">Profile Img.</label></td>
<td><input class="input-group" type="file" name="user_Picture or Picture or Image" accept="Picture or Image/*" /></td>
    </tr>
<tr>

<td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
        <span class="glyphicon glyphicon-save"></span>   Data save
        </button>
        </td>

    </tr>

    </table>

</form>
<div class="alert alert-info">
    <strong>tutorial link !</strong> <a href="https://pakainfo.com/2016/02/upload-insert-update-delete-Picture or Image-using.html">Coding Cage</a>!
</div>

</div>

<!-- New Latest compiled js and minified JavaScript(js) -->
<img src="data:image/gif" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</body>
</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()){
				?>
                <img src="data:image/gif;" />
                <?php
			}
			else{
				$Message_error = "Sorry Data Could Not Updated !";
			}
		
		}
		
						
	}
	

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

<html>
<head>
<title>Upload, Insert, Update, Delete an Picture or Image using PHP MySQL - Coding Cage</title>
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap.min.css">
<!-- linking - Optional - data theme -->
<link rel="stylesheet" href="Yourprojectfolder/css/bootstrap-theme.min.css">
<!-- link custom stylesheet -->
<link rel="stylesheet" href="Yourprojectfolder/style.css">
<!-- New Latest compiled js and minified JavaScript(js) -->
<img src="data:image/gif;" />

<img src="data:image/gif" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</head>
<body>
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
 
<div class="navbar-header">
            <a class="navbar-brand" href="https://pakainfo.com/" title='Programming Blog'>Coding Cage</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/php">PHP</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/javascript">JavaScript</a>
            <a class="navbar-brand" href="https://pakainfo.com/search/label/jQuery">jQuery</a>
        </div>
    </div>

</div>
<div class="container">
<div class="page-header">
<h1 class="h2">Welcome - update profile. <a class="btn btn-default" href="index.php"> all members </a></h1>
    </div>
<div class="clearfix"></div>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
    <?php if(isset($Message_error)){ ?>

<div class="alert alert-danger">
          <span class="glyphicon glyphicon-info-sign"></span>   <?php echo $Message_error; ?>
        </div>

        <?php } ?>
<table class="table table-bordered table-responsive">
	
<tr>
<td><label class="control-label">SalesuserName.</label></td>
<td><input class="form-control" type="text" name="sl_user_name" value="<?php echo $SalesuserName; ?>" required /></td>

    </tr>

<tr>

<td><label class="control-label">Profession(Job).</label></td>

<td><input class="form-control" type="text" name="title_user_job" value="<?php echo $SalespersonUser; ?>" required /></td>

    </tr>
<tr>
<td><label class="control-label">Profile Img.</label></td>
<td>
<img src="user_Picture or Images/<?php echo $salesuserimg; ?>" height="150" width="150" />

        	<input class="input-group" type="file" name="user_Picture or Image" accept="Picture or Image/*" />
        </td>

    </tr>
<tr>

<td colspan="2"><button type="submit" name="save_bttn_update_data" class="btn btn-default">
        <span class="glyphicon glyphicon-save"></span> Data Update
        </button>
        
        <a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-backward"></span> cancel Record </a>
        
        </td>

    </tr>
    </table>
</form>
<div class="alert alert-info">
    <strong>tutorial link !</strong> <a href="https://pakainfo.com/2016/02/upload-insert-update-delete-Picture or Image-using.html">Coding Cage</a>!
</div>
</div>
</body>
</html>

PHP crud Mysqli Select Insert Update and Delete query 0

PHP crud Mysqli Select Insert Update and Delete query

Today, We want to share with you PHP crud Mysqli Select Insert Update and Delete query.
In this post we will show you Mysqli Select Insert Update and Delete query, hear for Select Insert Update Delete In Php MySQLi Example we will give you demo and example for implement.
In this post, we will learn about PHP crud Mysqli Select Insert Update and Delete query 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.Mysqli Select Insert Update and Delete query

Mysqli SELECT,INSERT,UPDATE and DELETE Statement/Query

mysqli select query

$query_sql = "SELECT pageid, postname, catname,postid,postdesc FROM pakainfo";
$data_result = $conn->query($query_sql);

if ($data_result->num_rows > 0) {
    // looping through all data record output data of every row
    while($row = $data_result->fetch_assoc()) {
        echo "pageid: " . $row["pageid"]. " - postname: " . $row["postname"]. " " . $row["catname"]. "<br>";
    }
} 
else 
{
    echo "Not Found Data : 0 results display";
}

mysqli insert query

$sql_insert_query = "INSERT INTO pakainfo (pageid, pagename, catname)
VALUES ('p_124', 'Aboutus', 'general')";

if ($conn->multi_query($sql_insert_query) === TRUE) {
    echo "Good Luck : your New records database to created successfully..!!";
} else {
    echo "Error: " . $sql_insert_query . "<br>" . $conn->error;
}

mysqli Update query

$sql_update_query = "UPDATE pakainfo SET postname='contactus' WHERE postid=p2458";

if ($conn->query($sql_update_query) === TRUE) {
    echo "your data Record 100% updated successfully.!";
} else {
    echo "Not Update / Error updating record are : " . $conn->error;
}

mysqli Delete query

// sql to delete a record
$sql_delete_query = "DELETE FROM pakainfo WHERE postid=p2458";

if ($conn->query($sql_delete_query) === TRUE) {
    echo "your data Record particular deleted successfully: Good luck";
} else {
    echo "Not delete record yet../ Error deleting record are : " . $conn->error;
}

PHP mysqli insert update delete for Dynemic query 0

PHP mysqli insert update delete for Dynemic query

PHP mysqli insert update delete for Dynemic query

Today, We want to share with you PHP mysqli insert update delete for Dynemic query.
In this post we will show you PHP mysqli insert update delete for Dynemic query, hear for PHP mysqli insert update delete for Dynemic query we will give you demo and example for implement.
In this post, we will learn about PHP mysqli insert update delete for Dynemic query with an example.

Create-Read-Update-Delete(CRUD) statement query operation by using MySQLi statement way in the PHP.

The CRUD stands for simple Means Create statement, Read statement, Update statement and Delete statement database records. Add record, Edit record, Update record, and Delete record functionality is used almost web-applicaton or any dynamic webapps every web project in PHP.

ng4free.com In this Post Give to , PHP CRUD operations using MySQLi more simple and easy to user-friendlyinsert update delete in php mysqli with example

Three SQL commands Like as a – (INSERT, UPDATE and DELETE)– Main usually form the simple of any dynamic content management system.

Create Insert Query for dynamic Database

<?php
$tablename="pages";

if(isset($_POST['addpage']))
{
	$pname = $_POST['pname'];
	$ptitle = $_POST['ptitle'];
	$keywords = $_POST['keywords'];
	$pagedesc = $_POST['pagedesc'];
	$date = date("Y-m-d H:i:s");
	
	$arr = array('pmname' => $pname ,
				'lid'=>$lsid,
				'ptitle' => $ptitle,
				'pkeywords' => $keywords,
				'purl' => 	'',
				'pdesc' => $pagedesc
				);
	$columns = array_keys($arr);
	$values = array_values($arr);
	$str = $db->query("INSERT INTO $tablename (".implode(',',$columns).") VALUES ('" . implode("', '", $values) . "' )");

}
?>

Create Update Query for dynamic Database

<?php
if(isset($_POST['updatemenu']))
{
   $pname=$_POST['pname'];
   $ptitle=$_POST['ptitle'];
   $keywords=$_POST['keywords'];
   $pagedesc=$_POST['pagedesc'];
   $emid=$_POST['emid'];

   $tablename="pages";
   $arr_data = array('pmname' => $pname ,
				'ptitle' => $ptitle,
				'pkeywords' => $keywords,
				'pdesc' => $pagedesc
				);	
    $query = "UPDATE $tablename SET";
	$comma = " ";
	foreach($arr_data as $key => $val) {
		if( ! empty($val)) {
			$query .= $comma . $key . " = '" . mysql_real_escape_string(trim($val)) . "'";
			$comma = ", ";
		}
	}
	$query .=" where status=1 and pid='$emid'";
	$sql = $db->query($query);

}
?>

DELETE Query for dynamic Database

<?php
echo "<a href='do-delete.php?id=" . $row['id'] . "' alt="Delete records" title="Delete dynamic records">Delete Page</a>";

$id = $db->real_escape_string($_GET['id']); 
$db->query("DELETE FROM items WHERE id='$id'");
?>

DELETE Query for dynamic Database

<?php
delete($con, $tablename, $ColumnVal);

//delete function call
function delete($db, $tablename, array $val_cols){

    $i=0;
    foreach($val_cols as $key=>$value) {
        $exp[$i] = $key." = '".$value."'";
        $i++;
    }

    $sexper = implode(" AND ",$exp);
    if(mysqli_query($db,"DELETE FROM $tablename WHERE $sexper")){
        if(mysqli_affected_rows($db)){
            echo "deleted successfully<br>";
        }
        else{
            echo "want to the delete is no loger exists<br>";
        }
    }
    else{
        echo "Generate Error deleting for all the data: " . mysqli_error($db);
    }
}
?>

View Demo

We hope you get an idea about PHP mysqli insert update delete for Dynemic query
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.