forked from sushant-hiray/car-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
53 lines (49 loc) · 1.3 KB
/
functions.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
<?php
/*
* Common functions used throughout Codejudge
*/
session_start();
// connects to the database
function connectdb() {
include('dbinfo.php');
$con=mysql_connect($host,$user,$password);
if (!$con) {
die('Could not connect to mysql: ' . mysql_error());
}
mysql_select_db($database) or die('Error connecting to database. '. mysql_error());
}
// generates a random number.
function randomNum($length){
$rangeMin = pow(36, $length-1);
$rangeMax = pow(36, $length)-1;
$base10Rand = mt_rand($rangeMin, $rangeMax);
$newRand = base_convert($base10Rand, 10, 36);
return $newRand;
}
// checks if any user is logged in
function loggedin() {
return isset($_SESSION['username']);
}
function getUserid(){
$emailid=$_SESSION['username'];
$query="SELECT uid,name from users where email='".$emailid."'";
$result = mysql_query($query);
$fields = mysql_fetch_array($result);
$uid=$fields['uid'];
return $uid;
}
function name(){
$emailid=$_SESSION['username'];
$query="SELECT uid,name from users where email='".$emailid."'";
$result = mysql_query($query);
$fields = mysql_fetch_array($result);
$uid=$fields['name'];
return $uid;
}
function getName($uid){
$query="SELECT name from users WHERE uid=".$uid;
$res=mysql_query($query);
$result=mysql_result($res, 0);
return $result;
}
?>