PHP Classes

File: update_action.php

Recommend this page to a friend!
  Classes of Mehmet Kidiman   Developbat PHP CRUD   update_action.php   Download  
File: update_action.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Developbat PHP CRUD
Show pages to manage table records using Bootstrap
Author: By
Last change:
Date: 3 years ago
Size: 1,255 bytes
 

Contents

Class file image Download
<?php
error_reporting
(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

//var_dump($_POST);
include('config.php');
include(
'functions.php');

//return updateData($connect, $post);

$arrayKeys = array_keys($_POST);
$tableNamePost = $_POST['table_name_order'];
$primeryKeyName = $_POST['table_name_order_id'];
$primaryValue = $_POST[$primeryKeyName];


foreach (
$arrayKeys as $key){
    if(
$key == 'table_name_order' || $key == 'table_name_order_id' || $key == $primeryKeyName || $key == 'action'){

    }else{

       
$query = "
        UPDATE
$tableNamePost
        set
$key = :$key
        WHERE
$primeryKeyName = :$primeryKeyName
        "
;
       
$statement = $connect->prepare($query);
       
$statement->execute(
            array(
               
':'.$key => $_POST[$key],
               
':'.$primeryKeyName => $primaryValue,

            )
        );
       
$result = $statement->fetchAll();
        if(isset(
$result))
        {
           
$output = '<b>'.$tableNamePost.'</b> table <i> record with ' .$primaryValue . ' - ' . $primeryKeyName . '<i> is updated ';
        }else{
           
$output = '<b>'.$tableNamePost.'</b> table <i>' . $primaryValue . '<i> record Not Updated !! ';
        }

    }

}
echo
$output;