1

I am to php and I am trying to make a page where you can see the public uploads that are stored in a mysql server.

Out of not where the code I have been using starts giving me an error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'public' in 'where clause'

I am trying to see how many rows in my db have 'public'

// Find out how many items are in the table
$p = 'public';
$total = $db->query("SELECT COUNT(*) FROM uploads WHERE world_access = $p")->fetchColumn();

I don't know if it is the php or the sql.

// Prepare the paged query
$stmt = $db->prepare('SELECT * FROM uploads WHERE world_access = :y ORDER BY upload_time DESC LIMIT :limit OFFSET :offset');
// Bind the query params
$stmt->bindParam(':y', $p, PDO::PARAM_INT);
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();

pagination by Simple PHP Pagination script

Community
  • 1
  • 1
bakely
  • 61
  • 14
  • 2
    `$total = $db->query("SELECT COUNT(*) FROM uploads WHERE world_access = '$p'")->fetchColumn();` - Enclose `$p` with quotes. Also in your PDO, `:y` is string right? then use `PDO::PARAM_STR` – Thamilhan Jun 02 '16 at 04:23

1 Answers1

1

Enclose $p with quotes

$total = $db->query("SELECT COUNT(*) FROM uploads WHERE world_access = '$p'")->fetchColumn();

Also in your PDO, :y is string right? then use PDO::PARAM_STR

Thamilhan
  • 13,040
  • 5
  • 37
  • 59