Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php update multiple columns

$sql = "UPDATE product_list SET product_name='".$product_name."',product_category='".$product_category."',product_price='".$product_price."',product_description='".$product_description."',size_category='".$size_category."'";
Comment

Update Data Multiple Columns MySql Database Table PHP Function

//Update Data Into Multiple Columns
function updateAllColumns($table, $where = '', ...$params): bool
{
    global $db;
    $sql = "UPDATE $table SET ";
    foreach ($params[0] as $key => $val) {
        if ($val != 'NULL') {
            $sql .= "`{$key}`=" . "'{$val}' ,";
        } else {
            $sql .= "`{$key}`=" . ' NULL' . ",";
        }
    }
    if ($where) {
        $sql .= ' WHERE ' . $where . ' ';
    }
    $sql = substr_replace($sql, '', strrpos($sql, ','), 1);
    $result = $db->query($sql);

    if ($result) {
        return true;
    } else {
        return false;
    }
}
Comment

Insert Data Into MySql Database Multiple Columns PHP Function

//Insert Data Into Multiple Columns
//$params= Array Value array('me_title' => $_POST['me_title'])
function insertData($table, $params)
{
    global $db;
    $columns = array_keys($params);
    $values = array_values($params);
    $sql = "INSERT INTO $table (" . implode(',', $columns) . ") VALUES ('" . implode("', '", $values) . "' )";
    $result = $db->query($sql);
    $insertId = $db->getInsertId();
    if ($result) {
        return $insertId;
    } else {
        return false;
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php slice string by character 
Php :: session in laravel 
Php :: $ whereis php terminal mac 
Php :: validate number should by 12 digit in php 
Php :: confirm popup laravel 
Php :: update to php 7.4 
Php :: wordpress shortcode api 
Php :: date subtraction php 
Php :: php unset by value 
Php :: laravel get route action 
Php :: php += 
Php :: laravel "query()-find" 
Php :: php RFC3339 
Php :: crud operations in php 
Php :: Creating dynamic subdomain in php 
Php :: insert javascript in php 
Php :: how to know who added product in magento 
Php :: Call to undefined method IlluminateDatabaseEloquentRelationsHasMany::attach() 
Php :: compare key and one array 
Php :: php fn closure 
Php :: displaying php errors 
Php :: how to run a php file using 
Php :: php backend generator 
Php :: laravel validation rule 
Php :: laravel env in js 
Php :: join multiple query in laravel 
Php :: return last inserted id mysql opencart 
Php :: Custom search form 
Php :: Remove the additional notes area from the WooCommerce checkout 
Php :: Filtrer les articles WordPress mis en avant 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =