Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:03:35+00:00 2026-06-15T20:03:35+00:00

I’ve got such query: $sql = UPDATE test_accs SET acc_owner = ‘$owner_id’, acc_policy_version =

  • 0

I’ve got such query:

$sql = "UPDATE test_accs SET 
    acc_owner = '$owner_id', 
    acc_policy_version = '$version', 
    acc_policy_last_update = '$approved', 
    acc_policy_next_update = '$renewed' 
        WHERE acc_id = '1'";

Now, all of these values on the web folmular are optional, one can set one of these values, two, or so. Now, after I submit the form, it goes in the query like that:

UPDATE test_accs SET acc_owner = '2', acc_policy_version = '1.2', acc_policy_last_update = '2012-12-19', acc_policy_next_update = '2012-12-18' WHERE acc_id = '1'

It works only when I submit all values from the form. Can you please show me how could it work even if not all the values has been sent, just for example one of them?

When I set one value (f.ex. policy version), it looks like that:

UPDATE test_accs SET acc_owner = '', acc_policy_version = '1.2', acc_policy_last_update = '', acc_policy_next_update = '' WHERE acc_id = '1'

and it isn’t working.

It might be possible cause of the acc_owner table values?

#1366 - Incorrect integer value: '' for column 'acc_owner' at row 1

Thanks in advice.

Form:

echo '<td>Change owner: <select name="owner_id" onchange="showUser(this.value)" style="font-size:9px"><option value="">Select a person:</option>';
    while($owners = mysql_fetch_array($owners_query)) { echo '<option value="'.$owners['id'].'">'.$owners['surname'].' '.$owners['name'].'</option></h2>'; } echo '</select></td>';
    echo "<td><input name='version' style='width:50px;text-align:center' placeholder='0.0' /></td>";
    echo "<td><input name='approved' class='datepicker_all' readonly='readonly' style='text-align:center' placeholder='1999-01-01' /></td>";
    echo "<td><input name='renewed' class='datepicker_all' readonly='readonly' style='text-align:center' placeholder='1999-01-01' /></td>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:03:36+00:00Added an answer on June 15, 2026 at 8:03 pm

    One way to accomplish this is to use an expression in the SQL statement that tests whether the supplied value is an empty string. If the supplied value is an empty string, then use the current value of the column as the value to assign to the column. Otherwise, assign the supplied value to the column.

    In the example below, the each of the supplied values have to be include TWICE in the statement: once in the conditional test, and then again, as a possible result of the conditional test.

    This statement:

    UPDATE test_accs
       SET acc_owner              = IF('2'='',acc_owner,'2')
         , acc_policy_version     = IF('1.2'='',acc_policy_version,'1.2')
         , acc_policy_last_update = IF('2012-12-19'='',acc_policy_last_update,'2012-12-19')
         , acc_policy_next_update = IF('2012-12-18'='',acc_policy_next_update,'2012-12-18')
     WHERE acc_id = '1'
    

    is equivalent to the first UPDATE statement in the question, in that it sets the value of all four columns to the new specified value.

    This statement:

    UPDATE test_accs
       SET acc_owner              = IF(''='',acc_owner,'')
         , acc_policy_version     = IF('1.2'='',acc_policy_version,'1.2')
         , acc_policy_last_update = IF(''='',acc_policy_last_update,'')
         , acc_policy_next_update = IF(''='',acc_policy_next_update,'')
     WHERE acc_id = '1'
    

    changes ONLY the value of the acc_policy_version column, the values of the other three columns will remain unchanged.

    This is not necessarily the best approach, but it is workable for some scenarios.

    It’s also possible to create an expression that requires each supplied value be specified in the statement one time, although I think these expressions are a little less intuitive:

       SET acc_owner          = COALESCE(NULLIF( ''     ,''),acc_owner         )
         , acc_policy_version = COALESCE(NULLIF( '1.2'  ,''),acc_policy_version)
    

    That’s essentially doing the same thing as the examples above.

    If the supplied value is equal to ” (like it is for acc_owner in the example above), then the NULLIF expression will return a NULL. The COALESCE function essentially causes that NULL value to be skipped, and the current value of the column will remain unchanged (the current value of the column is assigned to the column.)

    If the supplied value is not equal to ” (like it is for acc_policy_version in the example above), then the NULLIF expression will return the supplied value. The COALESCE function will pick up that value, and assign it to the column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.