così
add_article.php:
codice:
<?phpsession_start();
if(isset($_POST['submit'])){
include 'article_functions.php';
include 'title_function.php';
$title = addslashes($_POST['titolo']);
$details = addslashes($_POST['descrizione']);
$meta_tag_title = addslashes($_POST['meta_tag_title']);
$meta_tag_details = addslashes($_POST['meta_tag_description']);
$pageClass= new pageClass();
$alert=$pageClass->addPage($title,$details,$meta_tag_title,$meta_tag_details);
$getArticle =$pageClass->getArticle($_POST['titolo']);
$value = $pageClass->getArticle($_POST['titolo']);
print_r($value);
$titleClass= new fileName();
$title = $titleClass->generateFilename($_POST['titolo'],30);
//$name_page_complete = str_replace(" ","_",$name_page_complete);
$fo = fopen($title,"w");
$code = '<?php include("article_functions.php");
$pageClass = new pageClass();
$id = '.$value['id'].';
$pageClass->getArticleById($id);
$value = $pageClass->getArticleById($id);
?>
<html>
<head>
<title><?php echo $value["meta_tag_titolo"];?></title>
<meta name="title" content="<?php echo $value["meta_tag_titolo"];?>">
<meta name="description" content="<?php echo $value["meta_tag_descrizione"];?>">
</head>
<body><?php echo $value["descrizione"]; ?>
<h1><?php echo $id; echo "'.$title.'"?></h1>
</body>
</html>';
fwrite($fo,$code);
fclose($fo);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Add</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//cdn.ckeditor.com/4.8.0/standard/ckeditor.js"></script>
</head>
<body>
<?php include 'include/header_admin.php'; ?>
<h1>Add Article</h1>
<form class="" action="add_article.php" method="post">
<label for="">Titolo</label><br>
<input type="text" name="titolo" value=""><br><br>
<label for="">Descrizione</label><br>
<input type="text" name="descrizione" id="descrizione" value="">
<label for="">Meta-tags Titolo</label><br>
<input type="text" name="meta_tag_title" value=""><br><br>
<label for="">Meta-tags Descrizione</label><br>
<input type="text" name="meta_tag_description" value=""><br><br>
<button type="submit" name="submit">Pubblica</button>
</form>
</body>
</html>
funzione addPage:
codice:
public function addPage($title,$details,$meta_tag_title,$meta_tag_details){
$conn = mysqli_connect("localhost","root","","tributi_comunali");
/*$title = $title;
$details = $details;
$meta_tag_title = $meta_tag_title;
$meta_tag_details = $meta_tag_details;*/
$insert="INSERT INTO articoli (titolo,descrizione,meta_tag_titolo,meta_tag_descrizione) VALUES ('$title','$details','$meta_tag_title','$meta_tag_details')";
$result=mysqli_query($conn,$insert);
if ($result) {
return "Values are added to our cms page";
}
else {
return "some errors";
}
}