Dynamic insert into with multiple values
<p>This is my <code>index.php</code> file and it has a simple form but with jscript I'll add some more inputs dynamically, then I need to insert these inputs to my database.</p>

<pre><code>&lt;form action="insert.php" method="post"&gt;
    &lt;input type="text" name="uid" placeholder="uid"&gt;
    &lt;input type="text" name="cid_1" placeholder="cid1"&gt;
    &lt;input type="text" name="cid_2" placeholder="cid2"&gt;
    &lt;input type="submit" value="Register" name="submit" /&gt;
&lt;/form&gt;
</code></pre>

<p>I've created <code>insert.php</code> as below. I just needed to type for each inputs but actually inputs will be added dynamically as I said, so I just need to apply while or foreach function I guess but I'm not that sure how to do, hope someone there can help me about this.</p>

<p>One more thing I need, In this case everything is working but it inserts everytime even if some inputs are empty. I could not found anything about this too.</p>

<p>Thank you for your help from now.</p>

<pre><code>&lt;?php
$link = mysqli_connect("localhost", "root", "", "test");

$uid = mysqli_real_escape_string($link, $_POST['uid']);
$cid1 = mysqli_real_escape_string($link, $_POST['cid_1']);
$cid2 = mysqli_real_escape_string($link, $_POST['cid_2']);

$sql = "INSERT INTO table (uid, cid) VALUES ('$uid', '$cid1'), ('$uid', '$cid2')";
mysqli_query($link, $sql)
?&gt;
</code></pre>