php function saveNews title category description source dt time sql IN

 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
<?php
function saveNews($title, $category, $description, $source){
$dt = time();
$sql = 'INSERT INTO msgs(title,category,description,source,datetime)
VALUES(:title,:category,:description,:source,$dt)';
$stmt = $this->_db->prepare($sql);
$stmt->bindParam(':title',$title);
$stmt->bindParam(':category',$category);
$stmt->bindParam(':description',$description);
$stmt->bindParam(':source',$source);
$result = $stmt->execute();
$stmt->close();
return $result;
}
if(!empty($_POST['title']) &&
!empty($_POST['description']) &&
!empty($_POST['source']) &&
!empty($_POST['category'])){
$title = strip_tags($_POST['title']);
$description = strip_tags($_POST['description']);
$source = strip_tags($_POST['source']);
$category = strip_tags($_POST['category']);
$result = $news->saveNews($title,$category,$description,$source);
if($result){
header('Location: news.php');
} else $errMsg[] = 'Произошла ошибка при добавлении новости';
} else {
$errMsg[] = 'Заполните все поля формы!';
}
?>