ThomasMcDonald
ThomasMcDonald

Reputation: 323

Laravel sqlite query error

Im receiving this error when i try and navigate to my comments page.

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

Heres 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 in 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 contents 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

Upvotes: 3

Views: 990

Answers (1)

jeroen
jeroen

Reputation: 91734

You have a problem here:

$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 2 values.

You would need:

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

Upvotes: 1

Related Questions