-2

I have a website that Facebook users use to get likes on their statuses. The website uses MySQL database to give likes to the users, the default number of limitation of the likes to be sent is 70. What I need is a PHP code that will let the user choose the amount of likes by themselves using the "select" HTML code.

I have already made the form and select codes (demo: jsfiddle.net/U4Ye8) Please see the demo.

The form action is "p.php"

The questions are:

-What code do I need to have in the index.php?

-What code do I need to have in the p.php?

If you need any other info about my question, please comment below.

$output = '';
   //get users and try liking
  $result = mysql_query("
      SELECT
         *
      FROM
         Likers ORDER BY ID DESC LIMIT 70
   ");



  if($result){
      while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
            $m = $row['access_token'];
            $facebook->setAccessToken ($m);
            $id = trim($_POST ['id']);
        try {
            $facebook->api("/".$id."/likes", 'POST');
            $msg1 = "<font color='get'>Success!</font>";
      }
       catch (FacebookApiException $e) {
            $output .= "<p>'". $row['name'] . "' failed to like.</p>";
            $msg2 = "<font color='red'>Failed to Like!</font>";
         }
}
}
user229044
  • 222,134
  • 40
  • 319
  • 330
user3213765
  • 77
  • 1
  • 1
  • 7

1 Answers1

0

Looks like you just need to set the limit to what was selected:

<select name="numOfLikes">            // <---- I gave your select a name
   <option value="##'>##</option>
</select>

SELECT * FROM Likers ORDER BY ID DESC LIMIT $_POST['numOfLikes']

Note** This is a sample script to see the changes easily. All $_POST and $_GET requests must be escaped for protection from sql injection. Prevent SQL Injection

Community
  • 1
  • 1
Tateyaku
  • 164
  • 9
  • Hey, where does the SELECT * FROM Likers ORDER BY ID DESC LIMIT $numOfLikes have to be? in the p.php or index.php? Because I have the html select code in the index.php and the SELECT FROM in p.php – user3213765 Mar 08 '14 at 23:04
  • exactly where it's at right now, in the p.php. just replace 70 with what ever variable you want to name your select form. – Tateyaku Mar 08 '14 at 23:06
  • Do not include user-supplied data in a query without escaping it, not _ever_! Especially not in an example for newbies! – Daniel Farrell Mar 08 '14 at 23:11
  • Hey, I have edited some stuff in your code and now it's WORKING!! :D Thanks man This is what I have done: $number = $_POST['number']; Likers ORDER BY ID DESC LIMIT $number – user3213765 Mar 08 '14 at 23:29
  • Well, now you're vulnerable to SQL Injection attacks. Good job @Tateyaku – Daniel Farrell Mar 08 '14 at 23:43