/
checkuser.php
50 lines (41 loc) · 1.36 KB
/
checkuser.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
<?php
/* checkuser.php */
// NOT USED!!!
// This file is called from the JavaScript AJAX function
// checkUser( user ) located in 'signup.php'. It determines
// what text to show the user while picking a username,
// and bases its decision on whether or not the desired
// username already exists in the database. Hence, it
// queries the database, and requires 'konfunctions.php'.
require_once 'konfunctions.php';
// Only execute something if $_POST['user'] is not empty.
if ( isset($_POST['user']) ) {
// Remove any security hazards from $_POST['user']
$user = sanitizeString( $_POST['user'] );
/* BEGIN Query 'users' database for a */
/* record that contains $_POST['user]' */
// Prepare the query statement
$queryUsers = "SELECT * FROM users WHERE user=':user'";
// try to query the database
try {
$query = $konnection->prepare($queryUsers);
$query = bindParam(':user', $user, PDO::PARAM_INT);
$query->execute();
$result = $query->fetch(PDO::FETCH_NUM);
}
catch( PDOException $e ) {
echo $sql."<br>".$e-getMessage();
}
/* END Query 'users' database */
// Check if the query returned any results
// and return the appropriate response message
if ( $result[0]['user'] != "" ) {
echo "<font color=red> ←
Sorry, already taken</font>";
}
else {
echo "<font color=green> ←
Username available</font>";
}
}
?>