-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.json
65 lines (47 loc) · 1.65 KB
/
delete.json
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
58
59
60
61
62
63
64
65
<?
//***********
// require local conf
require "plainnoteconf.php";
require "sqltojson.php";
// require the inspekt library
require "Inspekt/Inspekt.php";
// create a "SuperCage" to wrap all possible user input
// the SuperCage should be created before doing *anything* else
$input = Inspekt::makeSuperCage();
//ensure the user sent a user and pass
$username = $input->post->testEmail('username');
$account_id = $input->post->getRaw('account_id');
$post_id = $input->post->getRaw('post_id');
if (!$username || !$account_id || !$post_id) {
//bad user/account_id or missing param
echo json_encode(array ('status'=>400, 'error'=>'malformed request'));
}
else {
mysql_connect($dbHost,$dbUser,$dbPass);
@mysql_select_db($dbName) or die( "Unable to select database");
//first things first get the userpk
$query="SELECT userpk,username,password,guid FROM users where username='$username' and guid='$account_id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
if($num>0){
//found the user lets load some values
$d_userpk=mysql_result($result,$i,"userpk");
$d_username=mysql_result($result,$i,"username");
$d_password=mysql_result($result,$i,"password");
$d_guid=mysql_result($result,$i,"guid");
}
else{
echo json_encode(array ('status'=>400, 'error'=>'user not found'));
}
$sql = "DELETE FROM notes WHERE noteguid='$post_id'";
mysql_query($sql);
If(mysql_affected_rows()>0){
echo json_encode(array ('status'=>201, 'error'=>'success'));
}
else{
echo json_encode(array ('status'=>400, 'error'=>'note not deleted possibly did not exist?'));
}
mysql_close();
}
//all done
?>