-
Notifications
You must be signed in to change notification settings - Fork 1
/
like.php
57 lines (38 loc) · 1.08 KB
/
like.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// DB Connect
include("db.php");
if(isset($_GET['method'])){
if($_GET['method']=="Post"){
$UID = $_GET['UID'];
$CardID = $_GET['CardID'];
if($UID){
$query = "INSERT INTO likes (UID,CardID,Likes) VALUES ($UID, $CardID, 1)";
mysql_query($query) or die('Error, insert query failed');
}
}
else{
$CardID = $_GET['CardID'];
$query = "SELECT SUM(Likes) as total_likes FROM likes WHERE CardID =". $CardID;
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo $row['total_likes'];
}
}
mysql_close($conn);
}
?>
<form action="like.php" method="get">
<fieldset>
<p>User ID <input type="text" name="UID" id="UID" /></p>
<p>Card ID <input type="text" name="CardID" id="CardID" /></p>
<p>Method <select name="method">
<option>Post</option>
<option>Get</option>
</select></p>
<p>If you use get, u need the card ID.. I will output the number of likes</p>
</fieldset>
<fieldset>
<p><input type="submit" value="Like this card" /></p>
</fieldset>
</form>