title: How to retrieve data from mysql array and make checkbox checked in a form
body: <p>i have a problem retrieving data from mysql array, what i want to do is, when user open the same form next time for existing ID, he should see which option is checked, and which not, so, if he submit the form without changing anything (on checkbox), it'll be the same again.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>$media_array = $_POST['nesto1'];
  foreach ($media_array as $one_media) {
  $source .= $one_media.", ";
  }
  $nesto1 = substr($source, 0, -2);
  
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData" /&gt; NewData &lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData2" /&gt; NewData2 &lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData3" /&gt; NewData3 &lt;/label&gt;
  </code></pre>
  
  <p>Here's how i retrieve the data:</p>
  
  <pre><code>$result = mysql_query("SELECT * FROM `article` WHERE id=".intval($_GET["id"])." ORDER BY id ASC");
  $row = mysql_fetch_array($result);
  </code></pre>
  
  <p>How should i make checkbox option to be checked on next open, for example, NeData and NewData3, if i have values in my mysql row as: NewData, NewData3.</p>
  
  <p>I have tried with in_array, but i didn't success and here's what i have tried:</p>
  
  <pre><code>&lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData"&lt;?php echo in_array("NewData",$nesto1)?" checked="checked"":""; ?&gt; /&gt;NewData&lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData2"&lt;?php echo in_array("NewData2",$nesto1)?" checked="checked"":""; ?&gt; /&gt;NewData2&lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="NewData3"&lt;?php echo in_array("NewData3",$nesto1)?" checked="checked"":""; ?&gt; /&gt;NewData3&lt;/label&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>New code (i have changed values, array and syntax error is fixed now):</p>
  
  <p>if(isset($_POST["name"]) &amp;&amp; isset($_POST["change"]) &amp;&amp; isset($_POST["nesto2"]) &amp;&amp; is_numeric($_POST["change"])){
      $id = intval($_GET["id"]);</p>
  
  <pre><code>$name = mysql_real_escape_string($_POST["name"]);
  $nesto1 = mysql_real_escape_string($_POST["nesto1"]);
  $nesto2 = mysql_real_escape_string($_POST["nesto2"]);
  $change = mysql_real_escape_string($_POST["change"]);
  $type=  mysql_real_escape_string($_POST["category"]);
  $media_array = array();
  foreach ($media_array as $one_media) {
  $source .= $one_media.", ";
  }
  $nesto1 = substr($source, 0, -2);
  
  $result = mysql_query("SELECT * FROM `article` WHERE id=".intval($_GET["id"])." ORDER BY id ASC");
  $row = mysql_fetch_array($result);
  </code></pre>
  
  <p>form:</p>
  
  <pre><code>&lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="Kutija"&lt;?php echo in_array("Kutija",$nesto1)?" checked=\"checked\"":""; ?&gt; /&gt;Kutija&lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="Punjač"&lt;?php echo in_array("Punjač",$nesto1)?" checked=\"checked\"":""; ?&gt; /&gt;Punjač&lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="nesto1[]" value="Baterija"&lt;?php echo in_array("Baterija",$nesto1)?" checked=\"checked\"":""; ?&gt; /&gt;Baterija&lt;/label&gt;
  </code></pre>
  
  <p>Error: Warning: in_array() expects parameter 2 to be array, null given in /home/smarthos/public_html/articles/article/edit.php on line 142</p>