title: how to avoid duplication users in my db with php
body: <p>How are you all, </p>
  
  <p>hope every one here is OK,</p>
  
  <p>now I have a form that the admin can create users and he can delete users as will let me display the code first </p>
  
  <p>this is my code </p>
  
  <pre><code>&gt; &gt; &lt;?php error_reporting(E_ALL);
  &gt; 
  &gt; session_start();
  &gt;   if(!isset($_SESSION['login']) ||
  &gt; $_SESSION['login']!='1' )         {
  &gt;       header("Location:loginpage.php");
  &gt;       } ?&gt;
  &gt; 
  &gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD
  &gt; XHTML 1.0 Transitional//EN"
  &gt; "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &gt; &lt;html
  &gt; xmlns="http://www.w3.org/1999/xhtml"&gt;
  &gt; &lt;head&gt; &lt;meta http-equiv="Content-Type"
  &gt; content="text/html; charset=utf-8" /&gt;
  &gt; &lt;title&gt;My Control panel&lt;/title&gt; &lt;link
  &gt; href="../css_style.css"
  &gt; rel="stylesheet" type="text/css" /&gt;
  &gt; &lt;/head&gt;
  &gt; 
  &gt; 
  &gt; 
  &gt; &lt;body&gt; &lt;div id="werpper"&gt; &lt;div
  &gt; id="content"&gt;
  &gt; 
  &gt; &lt;div id="header"&gt;My control -
  &gt; Panel&lt;/div&gt; &lt;div id="body_cntent"&gt;  
  &gt; &lt;div id="left_side"&gt;   &lt;p&gt;Home and
  &gt; instructions&lt;/p&gt;   &lt;p&gt;&lt;a
  &gt; href="../control_panel.php"&gt;main
  &gt; directory&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;&lt;a
  &gt; href="add_event.php"&gt;Add new
  &gt; event&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;&lt;a
  &gt; href="../editoccasion.php"&gt;Control
  &gt; Occasion's&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;&lt;a
  &gt; href="add_photos_and_occasion.php"&gt;Add
  &gt; Photos_occasion&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;&lt;a
  &gt; href="../signout.php"&gt;Sign out&lt;/a&gt;&lt;/p&gt;
  &gt; &lt;/div&gt; &lt;div id="right_side"&gt;
  &gt; 
  &gt; &lt;h2&gt;Add new user&lt;/h2&gt;
  &gt; 
  &gt; &lt;form action="" method="post"&gt;
  &gt; 
  &gt; &lt;table width="600" border="0"
  &gt; cellpadding="5" cellspacing="0"&gt;  
  &gt; &lt;tr&gt;
  &gt;     &lt;td width="78"&gt;User name&lt;/td&gt;
  &gt;     &lt;td width="2"&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td width="149"&gt;&lt;input type="text" name="uname" value="" /&gt;&lt;/td&gt;
  &gt;     &lt;td width="332" rowspan="5" align="left" valign="top"&gt;&lt;p
  &gt; class="red"&gt;For Administration use
  &gt; only.&lt;/p&gt;
  &gt;       &lt;p&gt;You can add or delete users from &lt;a
  &gt; href="edit_users.php"&gt;here&lt;/a&gt;&lt;br /&gt;
  &gt;         You can't edit any user if you like to change any user account you
  &gt; can delete the user and create it
  &gt; again with the new
  &gt; information.&lt;/p&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;
  &gt;     &lt;td&gt;Password&lt;/td&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&lt;input type="text" name="pass" value="" /&gt;&lt;/td&gt;
  &gt;     &lt;/tr&gt;   &lt;tr&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&lt;input type="submit" name="submit" value="Add user" /&gt;&lt;/td&gt;
  &gt;     &lt;/tr&gt;   &lt;tr&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;/tr&gt;   &lt;tr&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;td align="right"&gt;&amp;nbsp;&lt;/td&gt;
  &gt;     &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt;
  &gt; 
  &gt; &lt;/div&gt; &lt;/div&gt;
  &gt; 
  &gt; &lt;div id="footer"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;
  &gt; 
  &gt; &lt;?php
  &gt;       if (isset($_POST['submit'])) {
  &gt;               include_once "../config/config.php";
  &gt;               $uname = $_POST['uname'];       $pass =$_POST['pass'];
  &gt;               $check = "select * from users where id = {$uname}";         $result_check
  &gt; = $db-&gt;query($check)or die($db-&gt;error);
  &gt;       
  &gt;               while ($row = $result_check -&gt; fetch_object()) {
  &gt;                       if(num_rows == 1){
  &gt;               
  &gt;               echo "error";
  &gt;               
  &gt;               }else{
  &gt;               $add_user = "insert into users (id, uname, pass) values ('',
  &gt; '$uname', '$pass')";
  &gt;               $result = $db -&gt; query($add_user) or die ("$db-&gt;error");
  &gt;               if ($result) {
  &gt;                       echo "user added successfuly";
  &gt;                       }else{
  &gt;               
  &gt;               echo "There was an error please try again later";
  &gt;               
  &gt;               }           }       }   } ?&gt;
  &gt; 
  &gt; &lt;/body&gt; &lt;/html&gt;
  </code></pre>
  
  <p>all I need here to know is how to solve the problem of this code </p>
  
  <pre><code>$check = "select * from users where id = {$uname}";
          $result_check = $db-&gt;query($check)or die($db-&gt;error);
  
  
          while ($row = $result_check -&gt; fetch_object()) {
  
              if(num_rows == 1){
  
                  echo "error";
  
                  }
  </code></pre>
  
  <p>how can I avoid duplication users in my db</p>