PHP: Create SQL query for available $_POST variable : <p>I have this $_POST Variable:</p>

<pre><code>Array
(
    [phone_1] =&gt; 3123213
    [phone_2] =&gt; 432423
    [phone_3] =&gt; 4234
    [phone_4] =&gt; 6456456
    [phone_5] =&gt; 7567576
    [phone_6] =&gt; 
)
</code></pre>

<p>Now I have this SQL statement:</p>

<pre><code>UPDATE table_name SET phone_1 = $_POST['phone1'],
phone_2 = $_POST['phone2'], 
phone_3 = $_POST['phone3'], 
phone_4 = $_POST['phone4'], 
phone_5 = $_POST['phone5'], 
phone_6 = $_POST['phone6'] 
WHERE id=$id
</code></pre>

<p>What I want to achieve is to dynamically build the SQL query based from the $_POST variable and only include those that have a post value. So the SQL statement should be:</p>

<pre><code>UPDATE table_name SET phone_1 = $_POST['phone1'],
    phone_2 = $_POST['phone2'], 
    phone_3 = $_POST['phone3'], 
    phone_4 = $_POST['phone4'], 
    phone_5 = $_POST['phone5']
</code></pre>

<p>because phone_6 post variable is blank. And yes the $_POST key names is the same as the table field names. TIA!</p>
