Laravel sqlite query error

I am getting this error when I try to navigate to the comments page.

SQLSTATE[HY000]: General error: 25 bind or column index out of range

Here is the function that queries the database:

function statusAndcomments($id)
{
    $sql = "Select * FROM status, comment WHERE user_Id = ?";
    $results = DB::select($sql, array($id,$id));   

    return $results;
}

      

which is called on the route:

Route::get('comments_post/{id}', function($id)
{
    $results = statusAndcomments($id);
    return View::make('Social.comments_post')->withComments($results);
});

      

And here is the code that uses the content from the database:

@section('content')
@forelse ($comments as $comment)
<div class="panel panel-default">

     <div class="panel-heading">{{{ $comment->Name }}} - {{{ $comment->Title }}}</div>
          <div class="panel-body">
                <img class='ProfilePic' src='../Images/defaultProfile.jpg' alt='Profile Picture'>
                <div>
                    <p>{{{ $comment->Message }}}</p>
                </div>
              </div>
    <div class="panel-footer">
            <form method="post" action="commentPoster">
            <input name ="comment" class="form-control" AUTOCOMPLETE=OFF  placeholder="Write a comment...">
            </form>
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">{{{ $comment->comment.name }}}</div>
    <div class="panel-body">
        <p>{{{ $comment->comment.comment }}}</p>
    </div>
    <div class="panel-footer"></div>
</div>
@empty
     No Posts
    @endforelse

  <a href="#" class="cd-top">Top</a>
@stop

      

+3


source to share


1 answer


You have a problem:

$sql = "Select * FROM status, comment WHERE user_Id = ?";
$results = DB::select($sql, array($id,$id)); 

      

Note that you only have one place holder, but you are sending an array with two values.



You will need:

$sql = "Select * FROM status, comment WHERE user_Id = ?";
$results = DB::select($sql, array($id)); 

      

+1


source







All Articles