title: Return variables from within a function and echo them
body: <pre><code>function loaditem() {
  
  global $connection;
  $item_Id = escape($_GET['edit_item']);
  
  
  $query = "SELECT * FROM stock_management WHERE ID = $item_Id ";
  $select_item = mysqli_query($connection, $query);
  while($row = mysqli_fetch_assoc($select_item)) {
      $id = escape($row['ID']);
      $image = escape($row['item_image']);
      $name = escape($row['prod_name']);
      $supplier = escape($row['supplier_name']);
      $pexvat = escape($row['P_PRICE_EXVAT']);
      $sellprice = $row['P_SELL'];
      $size = $row['SIZE'];
      $stock =$row['stock_level'];
      $lastpurchase = $row['L_PURCHASE'];
      $Stock_Location = $row['Stock_Location'];
  
  }
  
  }
  </code></pre>
  
  <p>Right so here's my problem I have this function to query my database and retrieve the following information. now the problem I'm having is retrieving the said values out of the function on the page I'm calling it for example im trying to echo in a text field </p>
  
  <pre><code>&lt;?php echo htmlspecialchars(stripslashes($name));?&gt;
  </code></pre>
  
  <p>But it just keeps saying undefined variable i've tried returning  <code>return $name;</code> with no luck so im hoping one of you guys can explain what im doing wrong</p>