0

Hi There I have a table that iterates like so

    <form method="get" action="search">
    <table class="bordered">
      <thead>
        <tr><th>No.</th><th>Post Username</th><th>Post Title</th><th>Post</th><th>Delete This post</th><td>Update This Post</td></tr>
      </thead>
      <tbody>
@foreach ($posts as $post)
        <tr>
          <td>{{{ $post->id }}}</td>
          <td>{{{ $post->post_username }}}</td>
          <td>{{{ $post->post_title }}}</td>
          <td>{{{ $post->post_message }}}</td>
          <td>
            <form method="post" action="{{{ url('delete_post_action') }}}">
            <input type="submit" value="{{ $post->id }}">Delete</td>
            </form>
          </td>
          <td><button name="update" value="{{ $post->id }}">Update</button></td>
        </tr>
@endforeach
    </tbody>
  </table>
  </form>

Which connects to this route.

Route::post('delete_post_action', function()
{
    $sql = "select * from posts";
    $current_posts = DB::select($sql);

    $results=$current_posts;

    return View::make('pages.home')->withposts($results);
});

  function delete_item($id)
  {
    $id = $post->id;
    $sql = "delete from posts where id = ?";
    DB::delete($sql, array($id));
  }

I have no idea why it isn't working. It refreshes the page as intended and updates the table. But it is not deleting any rows!

3
  • But how would i reference the id? I tried $id = $post->id; but no dice. Commented Apr 27, 2015 at 18:24
  • from what i see you are not referencing the id properly. Commented Apr 27, 2015 at 18:26
  • Sorry for my ignorance, but I am not sure what you mean? how would I do so? Where would it go in the function? I am having some severe struggles here. Commented Apr 27, 2015 at 18:28

1 Answer 1

1
Concatenate id you are injecting with your query would result in below 

        function delete_item($id)
          {
            $id = $post->id;
            $sql = "delete from posts where id='".$id."'";
            DB::delete($sql);
            return View::make('pages.home')
          }
Sign up to request clarification or add additional context in comments.

1 Comment

let me add a return to it the function. ideally there should be return @ the end of the function

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.