<?php

function D_news_entry($news){
  //var_dump($news);
  $conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);

  if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
    $qq="SELECT id FROM `".$GLOBALS['table1']."`";
    $query = $conn->query($qq);
    if ($query->num_rows > 0) $news["news_link"]=$news["news_link"].time();
  mysqli_set_charset($conn,"utf8");
  $stmt = $conn->prepare("INSERT INTO ".$GLOBALS['table1']." (`N_TITLE`, `N_LINK`, `N_CONTENT`, `PICS`, `LANG`, `N_DATE`,`N_CATEGORY`) VALUES (?, ?, ?, ?, ?, ?, ?)");
  $N_DATE=date('Y-m-d H:i:s');
  $stmt->bind_param("sssssss", $news["news_title"],$news["news_link"],$news["news_content"],$news["image"],$news["lang"],$N_DATE,$news["news_category"]);

  if($stmt->execute()){
    $GLOBALS['alert_info']= '<div class="alert alert-dismissible alert-info">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <strong>Yes!</strong> Entry Saved successfully 
  <br> Title :'.$news["news_title"].'
  <br> Link :'.$news["news_link"].'
  <br> Image :'.$news["image"].'
  </div>';
  }else{
    $GLOBALS['alert_info']= '<div class="alert alert-dismissible alert-danger">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <strong>Sorry!</strong> Unable to process db</div>';
  }
  $stmt->close();
  $conn->close();
}
?>
