-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddentry.php
More file actions
52 lines (49 loc) · 1.09 KB
/
addentry.php
File metadata and controls
52 lines (49 loc) · 1.09 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
<?php
session_start();
require 'config.php';
$db = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
if(isset($_SESSION['USERNAME'])==FALSE){
header("Location:".$config_basedir);
}
if($_POST['submit']){
$sql = "insert into entries(cat_id,dateposted,subject,body) values(".$_POST['cat'].",now(),'".$_POST['subject']."','".$_POST['body']."');";
$db->query($sql);
header("Location:".$config_basedir);
}else{
require 'header.php';
?>
<h1>Add new entry</h1>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<table>
<tr>
<td>Category</td>
<td>
<select name="cat">
<?php
$sql = "select * from categories";
$result = $db->query($sql);
while($row = mysqli_fetch_assoc($result)){
echo "<option value='".$row['id']."'>".$row['cat']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Subject</td>
<td><input type="text" name="subject"></td>
</tr>
<tr>
<td>Body</td>
<td><textarea name="body" rows="10" cols="50"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add Entry!"></td>
</tr>
</table>
</form>
<?php
}
require 'footer.php';
?>