-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_new_note_process.php
More file actions
72 lines (61 loc) · 1.97 KB
/
add_new_note_process.php
File metadata and controls
72 lines (61 loc) · 1.97 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
session_start();
require_once("db_connect.php");
$title=isset($_POST['title']) ? trim($_POST['title']) : "";
$note=isset($_POST['note']) ? trim($_POST['note']) : "";
$_SESSION['title']="$title";
$_SESSION['note']="$note";
?>
<!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=="" || $note=="")
{
$_SESSION['message']="Please make sure that no fields are empty";
$_SESSION['messagetype']="error";
header("Location: add_new_note.php");
exit();
}
$note_code="Note00001";
$get_note_code=mysql_query("select * from `notes` order by note_code desc");
if($get_note_code==FALSE)
{
$_SESSION['message']="Error encountered selecting notes";
$_SESSION['messagetype']="error";
header("Location: add_new_note.php");
exit();
}
if(mysql_num_rows($get_note_code)>0)
{
mysql_data_seek($get_note_code,0);
$row_get_note_code=mysql_fetch_assoc($get_note_code);
$last_note_code=$row_get_note_code['note_code'];
$last_id=intval(substr($last_note_code,4,5));
$new_id=strval($last_id+1);
while(strlen($new_id)<5)
{
$new_id="0" . $new_id;
}
$note_code="Note" . $new_id;
}
$insert_sql=mysql_query("insert into `notes` set registration_id='".$_SESSION['current_user_reg_no']."', note_code='$note_code', title='$title', note='$note'");
if($insert_sql==FALSE)
{
$_SESSION['message']="Error encountered inserting into notes";
$_SESSION['messagetype']="error";
header("Location: add_new_note.php");
exit();
}
unset($_SESSION['title'],$_SESSION['note']);
$_SESSION['message']="Your note has been successfully added";
$_SESSION['messagetype']="success1";
header("Location: add_new_note.php");
exit();
?>
</body>
</html>