title: editing data with a form
body: <p>I am trying to edit data in my database but i cant get it to work.</p>
  
  <p>i have tried breaking the script down to basics and troubleshoot each part.</p>
  
  <p>The delete button works just fine but editting the data doesn't.</p>
  
  <p>Where have i gone wrong?</p>
  
  <p>my structure
  database = domains table = domains_info row = domain</p>
  
  <pre><code>&lt;?php include("header.php");
  
  //include database connection
  include 'db_connect.php';
  
  $action = isset( $_POST['action'] ) ? $_POST['action'] : "";
  if($action == "update"){
  //write query
  $query = "update domains_info 
  set
  domain = '".$mysqli-&gt;real_escape_string($_POST['domain'])."', 
  where id='".$mysqli-&gt;real_escape_string($_REQUEST['id'])."'";
  
  if( $mysqli-&gt;query($query) ) {
      echo "User was updated.";
  }else{
      echo "Database Error: Unable to update record.";
  }
  }
  if($action=='delete'){ //if the user clicked ok, run our delete query
  
  $query = "DELETE FROM domains_info WHERE id='".$mysqli-&gt;real_escape_string($_GET['id'])."'";
  if( $mysqli-&gt;query($query) ){
      echo "User was deleted.";
  }else{
      echo "Database Error: Unable to delete record.";
  }}
  
  $query = "select id, domain
              from domains_info
              where id='".$mysqli-&gt;real_escape_string($_REQUEST['id'])."'
              limit 0,1";
  
  $result = $mysqli-&gt;query( $query );
  $row = $result-&gt;fetch_assoc();
  
  $id = $row['id'];
  $domain = $row['domain'];?&gt;
  
  &lt;form action='#' method='post' border='0' class="well form-horizontal"&gt;
    &lt;fieldset&gt;
      &lt;label class="control-label" for="name"&gt;Domain&lt;/label&gt;
      &lt;div class="controls"&gt;
      &lt;input id="name" type="text" name="name" value="&lt;?php echo$domain; ?&gt;"&gt;
      &lt;input type='hidden' name='id' value='&lt;?php echo $id ?&gt;' /&gt;
  
      &lt;!-- we will set the action to edit --&gt;
      &lt;input type='hidden' name='action' value='update' /&gt;
      &lt;input type='submit' value='Edit' /&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;?php echo "&lt;a href='#' onclick='delete_user( {$id} );'&gt;Delete&lt;/a&gt;"; ?&gt; 
  &lt;script type='text/javascript'&gt;
  
  function delete_user( id ){
  //prompt the user
  var answer = confirm('Are you sure you want to delete &lt;?php echo$name; ?&gt;?');
  
  if ( answer ){ //if user clicked ok
  //redirect to url with action as delete and id of the record to be deleted
  window.location = 'deletecontact.php?id=' + id;
  } 
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>the error im getting is this</p>
  
  <pre><code>Database Error: Unable to update record.
  </code></pre>