3

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
1
  • I'm not familiar with it but maybe this line: $results = DB::select($sql, array($id,$id)); should contain only one instance of $id? like: $results = DB::select($sql, array($id)); Commented Apr 19, 2015 at 8:43

1 Answer 1

1

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)); 
Sign up to request clarification or add additional context in comments.

1 Comment

God damn it, I didn't even realise that, thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.