Skip to content
Newer
Older
100644 49 lines (46 sloc) 1.39 KB
2422448 @ertancan index
authored
1 <?php
bba17af @ertancan select
authored
2 connectToDb();
f6620a0 @ertancan actions
authored
3 $action=$_GET['action'];
3092190 @ertancan comments
authored
4 if($action=="get"){ //action=get
f6620a0 @ertancan actions
authored
5 getUpdates();
026d55b @ertancan location
authored
6 }else if($action=="status"){ //action=status&user_id=1&message=mesaj&ap=library
f6620a0 @ertancan actions
authored
7 $userId=$_GET['user_id'];
8 $message=rawurldecode($_GET['message']);
9 $ap=$_GET['ap'];
10 addStatus($userId,$message,$ap);
1fc46aa @ertancan echo true
authored
11 echo "true";
3092190 @ertancan comments
authored
12 }else if($action=="login"){//action=login&name=kamil
f6620a0 @ertancan actions
authored
13 $name=$_GET['name'];
14 newUser($name);
15 }
3092190 @ertancan comments
authored
16 disconnectFromDb();
bba17af @ertancan select
authored
17
3092190 @ertancan comments
authored
18 //Actions
bba17af @ertancan select
authored
19 function connectToDb(){
20 $user="wifind";
21 $password="wifi0102";
22 $database="wifind"; //Database adõ
f11939b @ertancan localhost
authored
23 mysql_connect("localhost",$user,$password);
bba17af @ertancan select
authored
24 @mysql_select_db($database) or die( "Unable to select database");
25 }
7fecfb5 @ertancan updates
authored
26 function getUpdates(){
4ec9490 @ertancan add status
authored
27 $query="SELECT * FROM Status JOIN User WHERE Status.user_id=User.id ORDER BY status_id DESC";
7fecfb5 @ertancan updates
authored
28 $result=mysql_query($query);
3831cf3 @ertancan encode
authored
29 $arr=array();
30 while ($row = mysql_fetch_assoc($result)) {
31 array_push($arr,$row);
32 }
33 echo json_encode($arr);
026d55b @ertancan location
authored
34 }
35 function addStatus($userId,$message,$ap){
36 $insertQuery="INSERT INTO Status(message,user_id,location) VALUES ('".$message."',".$userId.",'".$ap."')";
131e1ae @ertancan insert
authored
37 mysql_query($insertQuery);
4ec9490 @ertancan add status
authored
38 }
1044ce2 @ertancan new user
authored
39 function newUser($name){
64bc28e @ertancan typo fix
authored
40 $insertQ="INSERT INTO User(name) VALUES ('".$name."')";
00fa4c1 @ertancan query fix
authored
41 mysql_query($insertQ);
1044ce2 @ertancan new user
authored
42 echo mysql_insert_id();
43 }
bba17af @ertancan select
authored
44 function disconnectFromDb(){
45 mysql_close();
46 }
7fecfb5 @ertancan updates
authored
47
026d55b @ertancan location
authored
48 ?>
Something went wrong with that request. Please try again.