-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.php
66 lines (53 loc) · 1.47 KB
/
submit.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
57
58
59
60
61
62
63
64
65
66
<?php
$servername = "localhost";
$username = "geekhavendba";
$password = "Geek@2016";
$dbname = "geekhavendb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo"connection succesful";
}
catch(PDOException $e)
{
echo "Connection failed: ";
}
$uid=$_POST['uid'];
$name =$_POST['name'];
$sroll = $_POST['sroll'];
$initial = "select count(*) from students where rollnum = '".$sroll."'";
$sql_result = $conn->prepare($initial);
$sql_result->execute();
$numRows = $sql_result->fetchColumn();
if($numRows==0){
$try = "select count from mentors where rollnum='".$uid."'";
$sql_result = $conn->prepare($try);
$sql_result->execute();
$row = $sql_result->fetch();
$count = $row['count'];
if($count<=3)
{
$try2 = "update mentors set count = count + 1,student".$count."r = '".$sroll."',student".$count."n = '".$name."' where rollnum='".$uid."'";
$sql_result2=$conn->prepare($try2);
$sql_result2->execute();
$try3 = "insert into students(rollnum,mentor) values('".$sroll."','".$uid."')";
$sql_result= $conn->prepare($try3);
$sql_result->execute();
$initial = "select count(*) from students where rollnum = '".$sroll."'";
$sql_result4 = $conn->prepare($initial);
$sql_result4->execute();
$numRows2 = $sql_result4->fetchColumn();
echo $numRows2;
}
else
{
echo "-1";
}
}
else
{
echo "0";
}
//echo $row['rollnum'];
?>