-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
  • 232,980
  • 40
  • 330
  • 338
user3213765
  • 87
  • 1
  • 1
  • 8
  • WE'll need to see your database schema. Try `show create table X;` where X is the table in which you store the number you're having the user input. – erik258 Mar 08 '14 at 22:53
  • Hey Dan, here is the database code: jsfiddle.net/hRM78 – user3213765 Mar 08 '14 at 22:58
  • Please put your code in the question. Why are you using **JS** fiddle to share PHP code? – user229044 Mar 08 '14 at 22:59
  • @meagar My code is not working on any of the questions I post (It shows empty space), so I have to use JSfiddle :) – user3213765 Mar 08 '14 at 23:00
  • When you submit a question, you have to highlight your code then hit the "Code" button at top of the box. The one with the { }, or highlight the code and hit Control + K on your keyboard. – Tateyaku Mar 08 '14 at 23:01
  • Font tags have been deprecated for soooo long. Try `..` – erik258 Mar 08 '14 at 23:13

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
  • 154
  • 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! – erik258 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 – erik258 Mar 08 '14 at 23:43