Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update multiple columns in mysql using php

Here i am trying to update update multiple column values in mysql table using php.

$product_id = mysqli_real_escape_string($link, $_POST['product_id']);
$product_name = mysqli_real_escape_string($link, $_POST['product_name']);
$product_category = mysqli_real_escape_string($link, $_POST['product_category']);

$sql = "UPDATE product_list (product_name, product_category, product_price,product_description,product_size_category) VALUES ('$product_name', '$product_category', '$product_price', '$product_description', '$size_category')";
}"

i have 5 column values to be updated in table, i am using variable to save data and using that variable want to update the values in table how can i do that?

like image 510
CJAY Avatar asked Sep 07 '15 11:09

CJAY


People also ask

How do I update multiple columns in MySQL?

MySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.

How do you update multiple columns in one query?

We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.

How do you update multiple columns in SQL with different conditions?

To update multiple columns use the SET clause to specify additional columns. Just like with the single columns you specify a column and its new value, then another set of column and values. In this case each column is separated with a column.

How do I update all values in a column in MySQL?

To set all values in a single column MySQL query, you can use UPDATE command. The syntax is as follows. update yourTableName set yourColumnName =yourValue; To understand the above syntax, let us create a table.


1 Answers

 $sql = "UPDATE `product_list` SET 
       `product_name` = '$product_name', 
       `product_category` = '$product_category', 
       `product_price` = '$product_price', 
       `product_description` = '$product_description', 
       `product_size_category` = '$size_category' 
  where clause..... (if required) ";
like image 180
Shailesh Katarmal Avatar answered Oct 12 '22 18:10

Shailesh Katarmal