title: Error when trying to change mysql record with php Insert Error Duplicate entry '0' for key 'PRIMARY'
body: <p>I am trying to learn PHP and Mysql by writing a small page. Things seem to be somewhat working, but my code may be just that bad. I have emp_num as the primary key for the mysql database. I have a page called page.php which is below.</p>
  
  <pre><code>&lt;?php
  
  $mysqli = new mysqli('localhost','root','','train');
  
  
  if ($mysqli-&gt;connect_error) {
  die('Error : ('. $mysqli-&gt;connect_errno .') '. $mysqli-&gt;connect_error);
  }
  
  //MySqli Select Query
  $results = $mysqli-&gt;query("SELECT emp_num, name, supervisor FROM train2015 ORDER     BY name desc");
  print '&lt;table border="1"&gt;';
  while($row = $results-&gt;fetch_object()) {
  print '&lt;tr&gt;';
  print '&lt;td&gt;'.$row-&gt;emp_num.'&lt;/td&gt;';
  print '&lt;td&gt;'.$row-&gt;name.'&lt;/td&gt;';
  print '&lt;td&gt;'.$row-&gt;supervisor.'&lt;/td&gt;';
  print '&lt;td&gt;';
  print '&lt;a href="edituser.php?=$row[emp_num]""&gt;Edit&lt;/a&gt;';
  print '&lt;/td&gt;';
  print '&lt;/tr&gt;';
  }  
  
  print '&lt;/table&gt;';
  
  // close connection 
  $mysqli-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>This page displays the records in a table with a edit button next to each record. Once edit is clicked it goes to edituser.php. Code below
      
  
  <pre><code>$mysqli = new mysqli('localhost','root','','train');
  
  
  if ($mysqli-&gt;connect_error) {
  die('Error : ('. $mysqli-&gt;connect_errno .') '. $mysqli-&gt;connect_error);
  }
  
  mysql_connect(localhost,$username,$password);
  
  mysql_close();
  ?&gt;
  
  &lt;form method="post" action="includes/insert2.php" /&gt;
  
  &lt;table&gt;
  
  &lt;tr&gt;
  &lt;td&gt;Name:&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="name" value="&lt;?php echo "$row[name]" ?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;Supervisor:&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="supervisor" value="&lt;?php echo "$row[supervisor]" ?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I want this page to be used to edit the name and supervisor once the button is clicked. My code for the insert2.php to make the change after the button is clicked is below.</p>
  
  <pre><code>  &lt;?php
  // Your database info
  $db_host = 'localhost';
  $db_user = 'root';
  $db_pass = '';
  $db_name = 'train';
  
   if (!empty($_POST))
  {   
      $con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
      if ($con-&gt;connect_error)
          die('Connect Error (' . mysqli_connect_errno() . ') '.   mysqli_connect_error());
  
      $sql = "INSERT INTO train2015 (name, supervisor) VALUES (?,?)";
      if (!$stmt = $con-&gt;prepare($sql))
          die('Query failed: (' . $con-&gt;errno . ') ' . $con-&gt;error);
  
      if (!$stmt-&gt;bind_param('ss',$_POST['name'],$_POST['supervisor']))
          die('Bind Param failed: (' . $con-&gt;errno . ') ' . $con-&gt;error);
  
      if (!$stmt-&gt;execute())
              die('Insert Error ' . $con-&gt;error);
  
      echo "Record added";
      $stmt-&gt;close();
      $con-&gt;close();
      header("Location: http://localhost/addsuccess.php");
  
  
  }
  ?&gt;
  </code></pre>
  
  <p>When I click the button on edituser.php to update the records I get a message that says Insert Error Duplicate entry '0' for key 'PRIMARY' and this is where I am stuck.</p>
  
  <p>Thanks in advance.</p>