title: AFNetworking error :The operation couldn’t be completed. (Cocoa error 3840.)
body: <p>I send a post request to my server like this.:</p>
  
  <pre><code>-(Produkt*)fetchProductByID:(int)idNumber
  {
  
  NSString* command = @"fetchProduct";
  NSString* number = [NSString stringWithFormat:@"%d",idNumber];
  NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:
                                command, @"command",
                                number, @"id",
                                nil];
  
  [self commandWithParams:params onCompletion:^(NSDictionary *json)
   {
       //result returned
       NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];
       NSMutableArray* dics = [[NSMutableArray alloc]init];
  
       if ([json objectForKey:@"error"]==NULL &amp;&amp; [res count]&gt;0)
       {
           //success
           for(int i=0;i&lt;[[json objectForKey:@"result"]count];i++)
           {
               res = [[json objectForKey:@"result"] objectAtIndex:i];
               [dics addObject:res];
  
               NSLog(@"SPECIAL FETCHED PRODUKT:%@",res);
           }
       }
       else
       {
           //error
           NSLog(@"error:%@",[json objectForKey:@"error"]);
           res = [[json objectForKey:@"result"] objectAtIndex:0];
           NSLog(@"SPECIAL FETCHED PRODUKT:%@",res);
       }
  
   }];
  
  return NULL;
  
  }
  </code></pre>
  
  <p>But I always get this error: error:The operation couldn’t be completed. (Cocoa error 3840.)
  The index.php code looks like this:</p>
  
  <pre><code>&lt;?
   require("lib.php");
  require("QMServerAPI.php");
  
  header("Content-Type: application/json");
  
  switch ($_POST['command']) 
  {
    case "fetchAllProduct": //Different question
    fetchAllProduct(); 
    break;
  
    case "fetchProduct":
    fetchProduct($_POST['id']);
    break;
  
    case "insertProduct":
    insertProduct($_POST['name'], $_POST['artikelNr'],
     $_POST['anleitung'], $_POST['image'], $_POST['editDate'],
     $_POST['id']); 
    break;
  
    case "updateProduct":
    updateProduc($_POST['name'], $_POST['artikelNr'],
    $_POST['anleitung'], $_POST['image'], $_POST['editDate'],
    $_POST['id']);
    break;
   }
   ?&gt;
  </code></pre>
  
  <p>Here I execute the command.:</p>
  
  <pre><code>function errorJson($msg)
  {
    header('Content-type: application/json');
    print json_encode(array("error"=&gt;$msg));
    exit();
  }
  
  function fetchAllProduct()
  {
       //fetch all Products
       $result = query("SELECT * FROM Produkte");
       print json_encode($result);
  }
  
  function fetchProduct($id)
  {
        //fetch specific product 
        $result  = query("SELECT * FROM Produkte WHERE id = '122'");
        print jeson_encode($result);
   }
    function insertProduct($name, $artikelNr, $anleitung, $image, 
                $editDate, $id)
   {
  
    }
  
      function updateProduct($name, $artikelNr, $anleitung, $image, 
                $editDate, $id)
     {
     //update old product
     }
  ?&gt;
  </code></pre>
  
  <p>And here is the code for the query function.:</p>
  
  <pre><code>&lt;?
  
       //setup db connection
     $link = mysqli_connect("localhost","root","");
     mysqli_select_db($link, "QM");
  
     //executes a given sql query with the params and returns an array as result
      function query() {
     global $link;
    $debug = false;
  
     //get the sql query
    $args = func_get_args();
    $sql = array_shift($args);
  
       //secure the input
      for ($i=0;$i&lt;count($args);$i++) {
        $args[$i] = urldecode($args[$i]);
       $args[$i] = mysqli_real_escape_string($link, $args[$i]);
     }
  
     //build the final query
    $sql = vsprintf($sql, $args);
  
    if ($debug) print $sql;
  
     //execute and fetch the results
        $result = mysqli_query($link, $sql);
       if (mysqli_errno($link)==0 &amp;&amp; $result) {
  
    $rows = array();
  
    if ($result!==true)
    while ($d = mysqli_fetch_assoc($result)) {
       array_push($rows,$d);
    }
  
    //return json
    return array('result'=&gt;$rows);
  
   } else {
  
    //error
    return array('error'=&gt; $mysqli-&gt;error);
   }
  }
  </code></pre>
  
  <p>I dont know whats wrong, because when I just select all products it works fine. The error just come when I use WHERE.</p>
  
  <p>Thanks for your help.</p>