Reputation: 89
I have this simple code for showing the list of books from my database:
<html>
<head>
<title>
Bookshelf
</title>
</head>
<body>
<table border='4' cellpadding='5'>
<th>Options</th>
<th>Book ID</th>
<th>Title</th>
<th>Author</th>
<th>Released Year</th>
<th>ISBN</th>
<?php
foreach($books as $book)
{
?>
<tr>
<td>
<a href="http://localhost/Bookstore/index.php/bookstore/showupdate"><input type="button" value="Update"/></a>
<br>
**<a href="http://localhost/Bookstore/index.php/bookstore/deleteentry?id=<?php echo $book->['book_id']; ?>"><input type="button" value="Delete"/></a>**
</td>
<td><?php echo $book['book_id'] ?></td>
<td><?php echo $book['book_name'] ?></td>
<td><?php echo $book['book_author'] ?></td>
<td><?php echo $book['book_year'] ?></td>
<td><?php echo $book['book_isbn'] ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html
The bolded part would be my problem, It shows an error :
Parse error: syntax error, unexpected '[', expecting T_STRING or T_VARIABLE or '{' or '$' in C:\www\Bookstore\application\views\showbooks.php on line 26
Could someone show me a much efficient/easier way to delete an entry using this technique where I just click links beside my database entry on views and it will delete? I have done this technique with simple PHP code and it works but this time I have to use frameworks, specifically codeigniter.
Upvotes: 0
Views: 186
Reputation: 827
$book->['book_id'];
is bad syntax.
Use either $book->book_id
for an object, or $book['book_id']
for an array.
It appears that you're using an array, so the second one.
Upvotes: 3