forked from bdobry/hackathon2016
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaskquestion.php
More file actions
149 lines (110 loc) · 4.23 KB
/
Copy pathaskquestion.php
File metadata and controls
149 lines (110 loc) · 4.23 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
echo file_get_contents("head.php");
?>
<?php
echo file_get_contents("header.php");
include 'config.php';
if(isset($_COOKIE["user"])){
$username = $_COOKIE["user"];
}
if(isset($_POST['formSubmit']) == "Submit")
{
$errorMessage = "";
if(empty($_POST['formTitle']))
{
$errorMessage .= "<li>You forgot to enter a title!</li>";
}
if(empty($_POST['formCategory']))
{
$errorMessage .= "<li>You forgot to select the category!</li>";
}
if(empty($_POST['formQuestion']))
{
$errorMessage .= "<li>You forgot to enter a question!</li>";
}
$varTitle = $_POST['formTitle'];
$varCategory = $_POST['formCategory'];
$varQuestion = $_POST['formQuestion'];
if(empty($errorMessage))
{
$sql = "INSERT INTO questions (title, category_id, question ) VALUES (".
PrepSQL($varTitle) . ", " .
$varCategory . ", " .
PrepSQL($varQuestion) . ")";
$result = $dbc->query($sql);
header("Location: main.php");
exit();
}
}
// function: PrepSQL()
// use stripslashes and mysql_real_escape_string PHP functions
// to sanitize a string for use in an SQL query
//
// also puts single quotes around the string
//
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . $value . "'";
return($value);
}
?>
<div class="container">
<!-- Jumbotron Header -->
<header class="jumbotron fp-jt">
<h1>Ask question</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, ipsam, eligendi, in quo sunt possimus non incidunt odit vero aliquid similique quaerat nam nobis illo aspernatur vitae fugiat numquam repellat.</p>
</header>
<hr>
<div class="row">
<?php
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<div class="col-lg-6">
<div class="well well-sm"><strong><i class="glyphicon glyphicon-ok form-control-feedback"></i> Required Field</strong></div>
<div class="form-group">
<label for="formTitle">Title</label>
<div class="input-group">
<input type="text" class="form-control" name="formTitle" id="InputName" placeholder="Enter Title" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<div class="form-group">
<label for="InputCategory">Category</label>
<div class="input-group">
<div class="form-group">
<select name="formCategory" class="form-control" id="categoryselect">
<option value="" selected disabled>Please select</option>
<option value="1">Design</option>
<option value="2">Code</option>
<option value="3">Off topic</option>
</select>
</div>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<div class="form-group">
<label for="formQuestion">Question</label>
<div class="input-group">
<textarea name="formQuestion" id="InputMessage" class="form-control" rows="5" placeholder="Write your question here" required></textarea>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<input type="submit" name="formSubmit" id="submit" value="Submit" class="btn btn-primary pull-right">
</div>
</form>
</div>
</div>
<?php
echo file_get_contents("pagefooter.php");
?>
<?php
echo file_get_contents("footer.php");
?>