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.

Also Read :  PHP crud Mysqli Select Insert Update and Delete query

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);

}
?>

Also Read :  PHP MySQLi Advance Live Searching

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.

Also Read :  Block specific IP Addresses Website Access by Country using PHP

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

Leave a Reply

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