title: how to save checkbox value into database
body: <p>hi i have a checkbox and i want to save its value into DataBase if it checked and save different text if its not checked.</p>
  
  <p>i tried to this code , it works but if i have 2 checkboxe it doesn't work any more.</p>
  
  <p><strong>tried code in view.php :</strong></p>
  
  <pre><code>$ch = SELECT check FROM users;
  if($ch=="checked"){
      echo "checked";
  }else{
      echo "not checked";
  }
  </code></pre>
  
  <p><strong>html :</strong></p>
  
  <pre><code>&lt;form action="action.php" method="post" id="form"&gt;
  &lt;p&gt;checkbox: &lt;input type="checkbox" name="check" value="checked" /&gt;&lt;/p&gt;
  &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>action.php :</strong></p>
  
  <pre><code>&lt;?php
  
  define('DB_NAME', 'users');
  define('DB_USER', 'root');
  define('DB_PASSWORD', '');
  define('DB_HOST', 'localhost');
  
  $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  
  if (!$link) {
      die('Could not connect : ' . mysql_error());
  }
  
  $db_selected = mysql_select_db(DB_NAME, $link);
  
  if (!$db_selected) {
      die('Can not use '.DB_NAME . ' :  ' . mysql_error());
  }
  
  $check =$_POST['check'];
  
  $sql = "INSERT INTO users (check) VALUES ('$check')";
  
  echo "your informations were sent to our database click to come back";
  
  mysql_query($sql);
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p><strong>view.php :</strong></p>
  
  <pre><code>&lt;?php
  $dbname = "users";
  $username = "root";
  $password = "";
  $servername = "localhost";
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  
  if ($conn-&gt;connect_error) {
       die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT * FROM users";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
  
       while($row = $result-&gt;fetch_assoc()) {
           echo "checkbox : ". $row["check"];
       }
  } else {
  echo "&lt;a class='btsc'&gt;no one registrated if you want register complete the form&lt;/a&gt;";
  }
  
  $conn-&gt;close();
  ?&gt; 
  </code></pre>
  
  <p><strong>db :</strong></p>
  
  <p><a href="http://i.stack.imgur.com/xmoVc.jpg" rel="nofollow">http://i.stack.imgur.com/xmoVc.jpg</a></p>