-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_new_question_process.php
More file actions
89 lines (73 loc) · 2.69 KB
/
add_new_question_process.php
File metadata and controls
89 lines (73 loc) · 2.69 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
<?php
session_start();
require_once("db_connect.php");
$title=isset($_POST['title']) ? trim($_POST['title']) : "";
$question=isset($_POST['question']) ? trim($_POST['question']) : "";
$_SESSION['title']="$title";
$_SESSION['question']="$question";
$date_of_question=date("Y-m-d");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if($title=="" || $question=="")
{
$_SESSION['message']="Please make sure that no fields are empty";
$_SESSION['messagetype']="error";
header("Location: add_new_question.php");
exit();
}
$select_question_user_name=mysql_query("select * from `students` where registration_id='".$_SESSION['current_user_reg_no']."'");
if($select_question_user_name==FALSE)
{
$_SESSION['message']="Error encountered selecting users information";
$_SESSION['messagetype']="error";
header("Location: add_new_question.php");
exit();
}
mysql_data_seek($select_question_user_name,0);
$row=mysql_fetch_assoc($select_question_user_name);
$asked_by=$row['full_name'];
$question_id="Ques00001";
$get_question_id=mysql_query("select * from `questions` order by question_id desc");
if($get_question_id==FALSE)
{
$_SESSION['message']="Error encountered selecting questions";
$_SESSION['messagetype']="error";
header("Location: add_new_question.php");
exit();
}
if(mysql_num_rows($get_question_id)>0)
{
mysql_data_seek($get_question_id,0);
$row_get_question_id=mysql_fetch_assoc($get_question_id);
$last_question_id=$row_get_question_id['question_id'];
$last_id=intval(substr($last_question_id,4,5));
$new_id=strval($last_id+1);
while(strlen($new_id)<5)
{
$new_id="0" . $new_id;
}
$question_id="Ques" . $new_id;
}
$insert_question=mysql_query("insert into `questions` set registration_id='".$_SESSION['current_user_reg_no']."',question_id='$question_id',title='$title',question='$question',asked_by='$asked_by',answers='none',answered_by='none',date_of_question='$date_of_question'");
if($insert_question==FALSE)
{
$_SESSION['message']="Error encountered inserting into questions".mysql_error();
$_SESSION['messagetype']="error";
header("Location: add_new_question.php");
exit();
}
unset($_SESSION['title'],$_SESSION['question']);
$_SESSION['message']="Your question was successfully added!";
$_SESSION['messagetype']="success";
header("Location: add_new_question.php");
exit();
?>
</body>
</html>