Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question
    
So what's the problem you're having? – Acharya Anurag Sep 7 '15 at 12:02
    
possible duplicate of PHP: Update multiple MySQL fields in single query – Insane Skull Sep 7 '15 at 12:02
    
your query is insert query. not update query. Use update table_name set column_name = 'value' – Shailesh Katarmal Sep 7 '15 at 12:03
1  
@Mithun Please check your query. I think, you are confused with INSERT and UPDATE query. Refer the UPDATE query syntax here – Sivaprakash Sep 7 '15 at 12:10
up vote 2 down vote accepted
 $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) ";
share|improve this answer

You are mixing up query syntax between INSERT and UPDATE queries, the UPDATE syntax is ;

UPDATE TABLE SET col1 = val1, col2=val2... WHERE col1 = val

You shall use the UPDATE query as follows :

$sql = "UPDATE product_list SET product_name = '$product_name', 
product_category = '$product_category' WHERE product_id = $product_id";
share|improve this answer

Your query must be something like this :

"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 product_id='$product_id'
"
  1. make sure you define the variable you need like $size_category etc, cause i didn't see it.
  2. use conditions like where to update specific record
share|improve this answer

Try like this :

$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."' WHERE product_id=".$product_id;

Reference : https://dev.mysql.com/doc/refman/5.0/en/update.html

share|improve this answer

Update sql query, see flowing way.

Update database_tablename SET column_name1 = column_value1 , column_name2 = column_value2

$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."'";
share|improve this answer
    
Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually won't help the OP to understand their problem. – Reeno Sep 7 '15 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.