<?php 

$dir = '../../';

require_once $dir.'includes/main.php';

$errors = array();

$id = (int)$_GET['id'];

$sql = "SELECT * FROM listings WHERE id = '{$id}' LIMIT 1";
if(fetch_rows($sql) < 1){
   $errors[] = "Listing could not be found";
}else{
   $x = fetch_records($sql);
}

//check errors
if(!empty($errors)){
   $_SESSION['messages'] = $errors;
}else{

   // on success
   query("UPDATE listings SET status = 'active' WHERE id = '{$id}' LIMIT 1");
   $_SESSION['messages'][] = "Listing has been marked as approved";

}

header("location: ../listings/pending");
exit;

?>