forked from panxinwu/cj-message
-
Notifications
You must be signed in to change notification settings - Fork 1
/
youhui.php
executable file
·56 lines (49 loc) · 1.11 KB
/
youhui.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
<?php
error_reporting(E_ALL^E_NOTICE);
$xh = $_REQUEST['xh'];
if(!isset($xh))
{
$result = array(
"error" => 1,
"data" => "no have xh"
);
echo json_encode($result);
return;
}
if(strlen($xh) != 11) {
$result = array(
"error" => 2,
"data" => "学号应该是11位"
);
echo json_encode($result);
return;
}
$dbh = mysql_connect($_SERVER['DB_HOST'],$_SERVER['DB_USER'],$_SERVER['DB_PASSWORD']);
if(!$dbh){die("error");}
mysql_select_db('cj', $dbh);
$sql = sprintf(
"select * from youhui where xh = '%s'",
mysql_real_escape_string($xh)
);
$has = mysql_query($sql,$dbh);
$has_count = mysql_num_rows($has);
if($has_count != 0){
$result = array(
'error' => 202,
'data' => 'user exists'
);
echo json_encode($result);
return;
}
$sql = sprintf(
"insert into %s (xh) values ('%s')",
mysql_real_escape_string('youhui'),
mysql_real_escape_string($xh)
);
if(mysql_query($sql,$dbh)){
$result = array(
'error' => 0,
'data' => 'success'
);
echo json_encode($result);
}