1

Here's my like button:

<form method="POST">
    <input type="submit" value="Like">
    <input type="hidden" name="IP" value="<?php $_SERVER["REMOTE_ADDR"]; ?>">
</form>

Here's the PHP:

if (!empty($_POST)) {
  $connection = mysqli_connect("like");
  $statement = mysqli_prepare($connection, "INSERT INTO Like (User, PageId) VALUES (?, ?)");
  mysqli_stmt_bind_param($statement, "si", $_POST["IP"], $_GET["id"]);
  mysqli_stmt_execute($statement);
  exit;
}

Can I use a custom image instead of the standard button? And how do I display the amount of likes on the page?

I have two columns: IP and PageId.

Additionally, what is the "si" for? (didn't do that part myself).

Thanks!

thanksd
  • 54,176
  • 22
  • 157
  • 150
Iphd
  • 23
  • 7
  • 1
    `si` stands for `string` and `integer` respectively. You're telling the function that you're expecting your first bound variable to be a string and your second variable to be an integer. – DiddleDot Jan 17 '16 at 05:17
  • Ah, thanks. When I googled it, I just got a random bunch of spanish. – Iphd Jan 17 '16 at 05:22

1 Answers1

1

As commented, si stand for string and integer, you can find more details and the complete list at http://php.net/manual/en/mysqli-stmt.bind-param.php

As for having a custom image, you can google "make an image act like a button", or visit this Making an image act like a button

To return the number of likes you would have to query the database for the count of rows where PageId = $_GET["id"]

a simple query can be like select count(*) from Like where PageId = 10

Community
  • 1
  • 1
Mahmoud Tantawy
  • 713
  • 5
  • 12