1

This is my first attempt at a prepared statement and instead of returning a single text element, I'm getting a number instead. The number 1 to be specific. Somebody said its got something to do with counting the records but I'm not sure how to turn it off.

function primary_include2($url_keyword)
  {
    $link = select_db();
    $query = "select file_path FROM primary_includes WHERE url_label=?";
    $stmt = mysqli_prepare($link, $query);
    mysqli_stmt_bind_param($stmt, 's', $url_keyword);

    if ($result = mysqli_stmt_execute($stmt)); 
      {
        mysqli_stmt_bind_result($stmt, $file_path);
        $path = mysqli_stmt_fetch($stmt);
        return $path;
        }
    mysqli_close($link);
  }
Maelish
  • 1,600
  • 4
  • 18
  • 25

1 Answers1

1

It should be:

function primary_include2($url_keyword)
{
    $link = select_db();
    $query = "select file_path FROM primary_includes WHERE url_label=?";
    $stmt = mysqli_prepare($link, $query);
    mysqli_stmt_bind_param($stmt, 's', $url_keyword);

    if ($result = mysqli_stmt_execute($stmt)); 
    {
        mysqli_stmt_bind_result($stmt, $file_path);
        mysqli_stmt_fetch($stmt);
        return $file_path;
    }
    mysqli_close($link);
}

because mysqli_stmt_fetch returns true/false if a record was retrieved or not. The actual values are stored in variables indicated to mysqli_stmt_bind_result.

Andrei B
  • 2,740
  • 17
  • 12