-
Notifications
You must be signed in to change notification settings - Fork 6
/
insert.php
executable file
·71 lines (71 loc) · 2.6 KB
/
insert.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
67
68
69
70
71
<?php
session_start();
if (!isset($_SESSION['username'])) {
?><script>alert('Please login to contribute.');
window.location='index.php';</script>
<?php
}
$server = "localhost";
$username = "root";
$password = "";
$dbname = "survey";
$conn = mysqli_connect($server, $username, $password, $dbname);
if (!$conn) {
die("failed" . mysqli_error());
}
if (isset($_GET['form-submit']))
{
$crstech=$_GET['ctech'];
$query1="SELECT * from Languages where technology='$crstech';";
$result=mysqli_query($conn,$query1);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$rows=mysqli_num_rows($result);
if($rows==0)
{
$query2="INSERT into Languages values('$crstech',0);";
$result1=mysqli_query($conn,$query2);
if (!$result1) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
}
$crsname=$_GET['cname'];
$crslink=$_GET['clink'];
$crscost=$_GET['ccost'];
$crstype=$_GET['ctype'];
$crslevel=$_GET['clevel'];
$sql="SELECT * from Courses where link='$crslink';";
$res=mysqli_query($conn,$sql);
if (!$res) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$num_rows=mysqli_num_rows($res);
if($num_rows==0)
{
$sql1="INSERT into Courses (technology,course_name,link,dif_level,course_type,cost) values('$crstech','$crsname','$crslink','$crslevel','$crstype','$crscost');";
$res1=mysqli_query($conn,$sql1);
if (!$res1) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
else
{
echo "<script>
alert('Thanks for contributing to Tutoverflow.');
window.location.href='index.php';
</script>";
}
}
else
{
echo "<script>
alert('Sorry,this Tutorial already exists.');
window.location.href='index.php';
</script>";
}
}
?>