forked from nikolamilosevic86/SimpleWebSurvey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion_creator.php
More file actions
73 lines (67 loc) · 2.61 KB
/
question_creator.php
File metadata and controls
73 lines (67 loc) · 2.61 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
72
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
session_start();
$question_text = htmlentities($_POST['question_text']);
$question_image = htmlentities($_POST['question_image']);
$help_url_text = htmlentities($_POST['help_url_text']);
$help_url = htmlentities($_POST['help_url']);
$num_answers = htmlentities($_POST['num_answers']);
$_SESSION['num_answers'] = $num_answers;
$host = getenv('OPENSHIFT_MYSQL_DB_HOST');
$port = getenv('OPENSHIFT_MYSQL_DB_PORT');
$username = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
$password = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
$socker = getenv('OPENSHIFT_MYSQL_DB_SOCKET');
$db_name = "survey";
$conn = new mysqli($servername, $username, $password,$db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$question_text = $conn->real_escape_string($question_text);
$question_image = $conn->real_escape_string($question_image);
$help_url_text = $conn->real_escape_string($help_url_text);
$help_url = $conn->real_escape_string($help_url);
$num_answers = $conn->real_escape_string($num_answers);
$id_survey = $_SESSION['survey_id'];
if (!filter_var($help_url, FILTER_VALIDATE_URL) === false) {
} else {
die("$url is not a valid URL");
}
$sql = "INSERT INTO Questions (question_text, question_img, url,url_text,id_survay)
VALUES ('".$question_text."','".$question_image."','".$help_url."','".$help_url_text."',".$id_survey.");";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$id = $conn->insert_id;
echo "ID::::".$id;
$_SESSION['question_id'] = $id;
$conn->close();
?>
<html>
<head>
<title>Answers maker</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Add a potential answer</h1>
<form action="answer_creator.php" method="POST">
<table border="0">
<?php
for($i=0;$i<$num_answers;$i++){
?>
<tr><td>Text:</td> <td><input name="answer_text<?php echo $i?>" id="que_text" placeholder="Enter Question Text"/></td></tr>
<?php } ?>
<tr><td></td> <td> <input name="done_question" id="submit" value="Next Question" type="submit"/></td></tr>
</table>
</form>
</body>
</html>