-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddData.php
115 lines (98 loc) · 5.06 KB
/
addData.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
session_start();
if(isset($_POST['desc'])){
if(isset($_POST['iscorrect']) || $_POST['iscorrect']== ""){
echo "please check Data is missing";
// exit();
}
// exit();
}
require_once './connectin_db.php';
$question=$_POST['desc'];
$answer1=$_POST['answer1'];
$answer2=$_POST['answer2'];
$answer3=$_POST['answer3'];
$answer4=$_POST['answer4'];
$_SESSION['type']=$_GET['type'];
//$type= preg_replace('/[^a-z]/',"",$type);
$isCorrect=preg_replace('/[^0-9a-z]/',"",$_POST['iscorrect']);
$answer1=strip_tags($answer1);
$answer1=mysql_real_escape_string($answer1);
$answer2=strip_tags($answer2);
$answer2=mysql_real_escape_string($answer2);
$answer3=strip_tags($answer3);
$answer3=mysql_real_escape_string($answer3);
$answer4=strip_tags($answer4);
$answer4=mysql_real_escape_string($answer4);
$question=strip_tags($question);
$question=mysql_real_escape_string($question);
//if($type=='tf'){
//if((!$question) || (!$answer1) || (!$answer2) || (!$isCorrect)){
// echo 'sorry all field must be filed';
//}
//exit();
//}
//if($type=='mc'){
//if((!$question) || (!$answer1) || (!$answer2) || (!$answer3) || (!$answer4)|| (!$isCorrect)){
// echo 'sorry all field must be filed';
//}
//exit();
//}
$sql= mysql_query("Insert into questions (question,type) VALUES ('$question', '$_SESSION[type]')")or die(mysql_error());
$lastId= mysql_insert_id();
mysql_query("UPDATE questions SET question_id='$lastId' WHERE id='$lastId' LIMIT 1") or die(mysql_error());
if($_SESSION['type']=='tf'){
if($isCorrect== "answer1"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
if($isCorrect== "answer2"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
}
if($_SESSION['type']=="mc"){
if($isCorrect=="answer1"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer3','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer4','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
if($isCorrect=="answer2"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer3','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer4','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
if($isCorrect=="answer3"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer3','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer4','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
if($isCorrect=="answer4"){
$sql2= mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer4','1')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer1','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer2','0')") or die(mysql_error());
mysql_query("INSERT INTO answers(question_id,answer,correct) VALUES('$lastId','$answer3','0')") or die(mysql_error());
$msg='thankyou, your answers has been added';
header('location:addQuestion.php?msg='.$msg.'');
exit();
}
}
?>