top button
Flag Notify
Site Registration

Update MySql values with it's current value in php?

+1 vote
452 views

I have a column called name in a table info
So I want to update that with it's current value, like this name + user_input. I tried with this code but not working

mysql_query("UPDATE info SET name = name + '$user_input' WHERE id='$user_id'");

But It returns 0 and update column to 0....

Any idea how to accomplish this task?

posted Jun 15, 2014 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You should use CONCAT to concatenate string in MySQL (+ is for addition arithmetic operations which I guess can't properly work with names) :

UPDATE info SET name = CONCAT(name,'$user_input') WHERE id='$user_id'
answer Jun 16, 2014 by Rahul Singh
Similar Questions
+1 vote

My issue is that I have a PHP FORM that is submitting values through more than 55 input-text-fields, into a MySQL table.

Now, when I use UPDATE feature, suppose for e.g for 3 fields:

$sql="UPDATE pathology_test_rates SET bsugar_random='$bsugar_random', bsugar_fasting='$bsugar_fasting', bsugar_pp='$bsugar_pp'";

And then , if I want to update only 1 value, out of above 3, using PHP FORM, its making other 2 values empty. Whereas, I want other 2 values to remain un-disturbed.

How to do this ? Please help. M not using id in table.

–1 vote

I want to update my sql database record and want to populate the value of previous record. So anybody can help me to get the previous value of the record to show when the update require.

...