HTML/PHP Add News
[php]<?php
$pagetitle = “Upload”;
include “config.php”;
include “header.php”;
if(isset($_POST[‘name’]) && $steam->isLoggedin()) {
$result = $steam->addNewsData();
echo $result[‘message’];
}
?>
<strong>Title:</strong> <input name="name" type="text" id="name" />
<br />
<strong>Category:</strong>
<select name="type" id="type" />
<option value="Updates">Updates</option>
<option value="Steam Update">Steam Update</option>
</select>
<br />
<br />
<strong>Description:</strong>
<br />
<textarea cols="50" rows="5" id="description" name="description"></textarea>
<br />
<input type="submit" name="submit" value="Send">
HTML/PHP Edit News
[php]<?php
$pagetitle = “Updating News”;
include “config.php”;
include “header.php”;
if(isset($_POST[‘name’]) && $steam->isLoggedin()) {
$result = $steam->editNewsData($_GET[‘edit’]);
echo $result[‘message’];
}
if(isset($_GET[‘edit’]) && is_numeric($_GET[‘edit’])) {
$screenshot = $DB->getNewsById($_GET[‘edit’]);
if(isset($screenshot[‘uid’]) && $screenshot[‘uid’] == $steam->user[‘steamid’]) {
?>
Edit Title:
Edit Category: <?= h($screenshot['type']); ?>
Edit Description:
<?= h($screenshot['description']); ?>
PHP Add News Data
[php] function addNewsData() {
global $DB;
$status = 'error';
$message = 'You are not authorized to post news!';
if($this->isLoggedin()) {
//$id = 454;
// Verify the screenshot belongs to us
//$news = $DB->addNewsDataById($id);
$name = $_POST['name'];
$type = $_POST['type'];
$data = $_POST['description'];
if(empty($_POST['name']) || empty($_POST['type']) || $_POST['name'] == '' || $_POST['type'] == ''){
$message = "You Forgot To Fill the required Field Please Fix The Error";
} else {
$values = array(
'name' => $name,
'type' => $type,
'description' => $data
);
$id = $DB->insert('news', $values);
$status = 'success';
$message = 'You have successfully posted news.';
}
}
return array('status' => $status, 'message' => $message);
}[/php]
PHP Edit News Data
[php] function editNewsData($id) {
global $DB;
$status = 'error';
$message = 'You are not authorized to edit this news post.';
if($this->isLoggedin()) {
//$id = 454;
// Verify that this news post belongs to us
$news = $DB->getNewsById($id);
$name = $_POST['name'];
$type = $_POST['type'];
$description = $_POST['description'];
if(empty($_POST['name']) || empty($_POST['type']) || $_POST['name'] == '' || $_POST['type'] == ''){
$message = "You Forgot To Fill the required Field Please Fix The Error";
}
if(isset($image['id']) && is_numeric($id)) {
if($image['uid'] == $this->user['steamid']) {
// We have verified this is our news, lets edit it.
$values = array(
'name' => $name,
'type' => $type,
'description' => $description
);
$DB->update('news', $values, array('id' => $id));
$status = 'success';
$message = 'News has been updated.';
}
}
}
return array('status' => $status, 'message' => $message);
}[/php]
I am trying to be clear on my posts. What i am trying to do is get it so only myself can add news. But right now anyone who logs in can post lol. I am also using a steam api script not sure if I should post that as well or if this is enough. This website I am working on I am setting to launch an early alpha version end of next month. Still quiet a bit that needs to be done.
Thanks,
ZiG