-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofReg.php
More file actions
71 lines (56 loc) · 1.51 KB
/
profReg.php
File metadata and controls
71 lines (56 loc) · 1.51 KB
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
66
67
68
69
70
71
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h3> Please Write your personal information </h3><br>
Name:<br>
<input type="text" name="name" ><br><br>
ID:<br>
<input type="text" name="id" ><br><br>
Password:<br>
<input type="Password" name="pass" ><br><br>
<input type="submit" value="Regisrer">
</form>
<?php
if ($_SERVER['REQUEST_METHOD']=='POST'){
include 'connectDB.php' ; #connect database
if (checkid($_POST['id'],$db)){
if (strlen($_POST['name']) == 0 || strlen($_POST['id']) == 0 || strlen($_POST['pass']) == 0 ){
echo "Data missing !!! ";
} else {
register($_POST['name'] , $_POST['id'] , $_POST['pass'],$db);
echo '
<form action="profLogin.php">
You have created an account successfully
<input type="submit" value="Login">
</form>
';
}
} else {
echo "this professor ID is allready exist"."<br>";
}
}
function register($name , $id ,$pass ,$db)
{
try {
// our SQL statements
$db->exec("INSERT INTO Prof(Prof_id,Prof_pass, Name )
VALUES ('".$id."','".$pass."','".$name."')");
}
catch (PDOException $e){
echo 'Failed' . $e->getMessage();
}
}
function checkid( $value,$db)
{
$tableName = 'Prof' ;
$prop = 'Prof_id' ;
$columnName= 'Prof_id';
$q = $db->query("SELECT `$columnName` FROM `$tableName` WHERE $prop='".$value."'");
$f = $q->fetch();
$result = $f[$columnName];
if (is_null($result)){
return true ;
} else {
return false ;
}
}
echo '<a href="http://localhost:8080/QuestionBank/bank.php">Main page</a><br>';
?>