How to insert with a foreign key in the child table oophp
<p>UPDATE : I have two tables <strong>users</strong> And <strong>requests</strong>  users table has columns <strong>id username,password and town</strong> i can insert data in users successfully .requests table has <strong>id ,user_id ,product_name, proposed_price and request_description</strong> ,  where user_id is a foreign key referencing id from users table, the problem is that  insert data fails in requests table which has user_id as a foreign key . <strong>i get nothing in requests table</strong></p>

<p><strong>This function is supposed to be used in insertion:</strong> </p>

<pre><code>    public function  User_request ($product_name, $proposed_price, $request_description) {

     $qry = $this-&gt;conn-&gt;prepare("SELECT id FROM users WHERE id = ? ");
     $qry-&gt;bind_param("i", id);
     $result= $qry-&gt;execute();
     $user_id = $qry-&gt;fetch();
     $qry-&gt;close();

    if($user_id &gt; 0){

    $stmt = $this-&gt;conn-&gt;prepare("INSERT INTO  requests (user_id, product_name, proposed_price, request_description) VALUES(?, ?, ?, ?)");

    $stmt-&gt;bind_param("isss",$user_id, $product_name, $proposed_price, $request_description);
    $result = $stmt-&gt;execute();
    $stmt-&gt;close();

    // check for successful store
    if ($result) {
        $stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM requests WHERE request_description = ?");
        $stmt-&gt;bind_param("s", $request_description);
        $stmt-&gt;execute();
        $user = $stmt-&gt;get_result()-&gt;fetch_assoc();
        $stmt-&gt;close();

        return $user;
    } else {
        return false;
    }

    }
} 
</code></pre>

<p><strong>And below codes call above function:</strong> </p>

<pre><code>       &lt;?php

  include './DbHandler.php';
  $db = new DBHandler();

   // json response array
  $response = array("error" =&gt; FALSE);

 if ( isset($_POST['product_name']) &amp;&amp; isset($_POST['proposed_price']) &amp;&amp;        isset($_POST['request_description']) ) {

// receiving the post params
$product_name = $_POST['product_name'];
$proposed_price =$_POST['proposed_price'];
$request_description =$_POST['request_description'];

    // create a new request
    $user = $db-User_request($product_name, $proposed_price,    $request_description);
    if ($user) {
        // user stored successfully
        $response["error"] = FALSE;
        $response["user"]["username"] = $user["username"];
        $response["user"]["proposed_price"] = $user["proposed_price"];
        $response["user"]["request_description"] = $user["request_description"];

        echo json_encode($response);
    } else {
        // user failed to store
        $response["error"] = TRUE;
        $response["error_msg"] = "oops error occured!";
        echo json_encode($response);
    }
}
   else {
     $response["error"] = TRUE;
      $response["error_msg"] = "Required parameters are missing!";
     echo json_encode($response);
   }
  ?&gt;
</code></pre>