-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticle.php
45 lines (41 loc) · 1.72 KB
/
Article.php
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
<?php
error_reporting(E_ALL^E_NOTICE);
//insert a new article
if (!$_POST['article_id']){
$config = include 'config.php';
$db_host = $config['db_host'];
$db_user = $config['db_user'];
$db_pwd = $config['db_pwd'];
$db_name = $config['db_name'];
$conn = mysqli_connect("$db_host", "$db_user", "$db_pwd");
if (!$conn) {
echo "Can not connect to database";
}
mysqli_select_db($conn, $db_name);
date_default_timezone_set("America/Montreal");
$time = date("Y-m-d H:i:s", time());
$sql = "insert into Article (author_id,title,content,created_time,last_update) values('" . $_POST['id'] . "','" . $_POST['title'] . "','" . $_POST['content'] . "','" . $time . "','" . $time . "')";
mysqli_query($conn, $sql);
$sql = "select LAST_INSERT_ID()";
$res = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($res);
mysqli_close($conn);
} else{
// update a exist article
$config = include 'config.php';
$db_host = $config['db_host'];
$db_user = $config['db_user'];
$db_pwd = $config['db_pwd'];
$db_name = $config['db_name'];
$conn = mysqli_connect("$db_host", "$db_user", "$db_pwd");
if (!$conn) {
echo "Can not connect to database";
}
mysqli_select_db($conn, $db_name);
date_default_timezone_set("America/Montreal");
$time = date("Y-m-d H:i:s", time());
$sql = "update Article set title='". $_POST['title'] ."', content='". $_POST['content'] ."',last_update='". $time ."' where id='". $_POST['article_id'] ."'";
mysqli_query($conn, $sql);
mysqli_close($conn);
}
echo "success";