Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL update query, how to skip empty values?
    primarykey
    data
    text
    <p>I've got such query:</p> <pre><code>$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'"; </code></pre> <p>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:</p> <pre><code>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' </code></pre> <p>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?</p> <p>When I set one value (f.ex. policy version), it looks like that:</p> <pre><code>UPDATE test_accs SET acc_owner = '', acc_policy_version = '1.2', acc_policy_last_update = '', acc_policy_next_update = '' WHERE acc_id = '1' </code></pre> <p>and it isn't working.</p> <p>It might be possible cause of the acc_owner table values?</p> <pre><code>#1366 - Incorrect integer value: '' for column 'acc_owner' at row 1 </code></pre> <p>Thanks in advice.</p> <p>Form:</p> <pre><code>echo '&lt;td&gt;Change owner: &lt;select name="owner_id" onchange="showUser(this.value)" style="font-size:9px"&gt;&lt;option value=""&gt;Select a person:&lt;/option&gt;'; while($owners = mysql_fetch_array($owners_query)) { echo '&lt;option value="'.$owners['id'].'"&gt;'.$owners['surname'].' '.$owners['name'].'&lt;/option&gt;&lt;/h2&gt;'; } echo '&lt;/select&gt;&lt;/td&gt;'; echo "&lt;td&gt;&lt;input name='version' style='width:50px;text-align:center' placeholder='0.0' /&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;input name='approved' class='datepicker_all' readonly='readonly' style='text-align:center' placeholder='1999-01-01' /&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;input name='renewed' class='datepicker_all' readonly='readonly' style='text-align:center' placeholder='1999-01-01' /&gt;&lt;/td&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload