Jump to content

Recommended Posts

<?php ## Blog Manager?>

<?php
if (isset($_POST['submitted']) == 1) {
if ($_GET['id'] == '') {
if ($_POST['title'] =='' || $_POST['body'] == '') {
header('Location: index.php?page=blog');
} else {
$title = $_POST['title'];
$date = $_POST['date'];
$body = $_POST['body'];

$q = "INSERT INTO blog (title, date, body) VALUES ('$title', '$date', '$body')";
}
}else {
$q = "UPDATE blog SET title = '$_POST[title]', date = '$_POST[date]', body = '$_POST[body]' WHERE id = '$_POST[id]'";
}
$r = mysqli_query($dbc, $q);
}

?>
< h2>ATOM.CMS Blog Manager</h2>

<div class="col sidebar">

<ul class="nav_side">

<li><a href="?page=blog">+ Add Post</a></li>

<?php

$q = "SELECT * FROM blog ORDER BY date ASC";
$r = mysqli_query($dbc, $q);

if ($r) {

while ($link = mysqli_fetch_assoc($r)) {

echo '<li><a href="?page=blog&id='.$link['id'].'">'.$link['title'].'</a></li>';

}
}
?>

</ul>


< /div>
< div class="col editor">
< h1>
<?php

if (isset($_GET['id'])) {

$q = "SELECT * FROM blog WHERE id = '$_GET[id]' LIMIT 1";

$r = mysqli_query($dbc, $q);
$opened = mysqli_fetch_assoc($r);

echo 'Editing: '.$opened['title'];

} else {

echo 'Add a New Blog Post';

}
?>
< /h1>


<form action="?page=blog&id=<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" method="post">

<table class="gen_form">

<tr>
<td class="gen_label"><label>Blog title: </label></td>
<td><input class="gen_input" type="text" size="30" name="title" value="<?php if (isset($_GET['id'])){echo $opened['title'];} ?>" /></td>
</tr>
<tr>
<td class="gen_label"><label>Blog date: </label></td>
<td><input class="gen_input" type="text" size="30" name="date" value="<?php if (isset($_GET['id'])){echo $opened['date'];} ?>"/></td>
</tr>
<tr>
<td class="gen_label"></td>
</tr>
<tr>
<td colspan="2" class="gen_label"><label>Blog body: </label></td>
</tr>
<tr>
<td colspan="2"><textarea id="page_body" name="body" cols="90" rows="24"><?php if (isset($_GET['id'])){echo $opened['body'];} ?></textarea></td>
</tr>
<tr>
<td colspan="2"><input class="gen_submit" type="submit" name="submit" value="Save Changes" /></td>
</tr>

<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="id" value="<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" />

</table>

</form>
<?php ?>

</div>

 

Two problems:

 

1. The timestamp being inserted into the database is 0000-00-00 00:00:00

2. The body content is being inserted into the database with paragraph tags around it (I am using Redactor WYSIWYG for the body field).

 

What could be causing these two issues?

Link to comment
https://forums.phpfreaks.com/topic/275574-timestamp-issue-and-wysiwyg-issue/
Share on other sites

Wrap your code in the code block. -> Button that looks like <>

 

<?php ## Blog Manager ?>
<?php
if (isset($_POST['submitted']) == 1) {
    if ($_GET['id'] == '') {
        if ($_POST['title'] == '' || $_POST['body'] == '') {
            header('Location: index.php?page=blog');
        } else {
            $title = $_POST['title'];
            $date = $_POST['date'];
            $body = $_POST['body'];

            $q = "INSERT INTO blog (title, date, body) VALUES ('$title', '$date', '$body')";
        }
    } else {
        $q = "UPDATE blog SET title = '$_POST[title]', date = '$_POST[date]', body = '$_POST[body]' WHERE id = '$_POST[id]'";
    }
    $r = mysqli_query($dbc, $q);
}
?>
< h2>ATOM.CMS Blog Manager</h2>
<div class="col sidebar">
    <ul class="nav_side">

        <li><a href="?page=blog">+ Add Post</a></li>

        <?php
        $q = "SELECT * FROM blog ORDER BY date ASC";
        $r = mysqli_query($dbc, $q);

        if ($r) {

            while ($link = mysqli_fetch_assoc($r)) {

                echo '<li><a href="?page=blog&id=' . $link['id'] . '">' . $link['title'] . '</a></li>';
            }
        }
        ?>

    </ul>

    < /div>
    < div class="col editor">
    < h1>
<?php
if (isset($_GET['id'])) {

    $q = "SELECT * FROM blog WHERE id = '$_GET[id]' LIMIT 1";

    $r = mysqli_query($dbc, $q);
    $opened = mysqli_fetch_assoc($r);

    echo 'Editing: ' . $opened['title'];
} else {

    echo 'Add a New Blog Post';
}
?>
    < /h1>

    <form action="?page=blog&id=<?php if (isset($_GET['id'])) {
        echo $opened['id'];
    } ?>" method="post">

        <table class="gen_form">

            <tr>
                <td class="gen_label"><label>Blog title: </label></td>
                <td><input class="gen_input" type="text" size="30" name="title" value="<?php if (isset($_GET['id'])) {
        echo $opened['title'];
    } ?>" /></td>
            </tr>
            <tr>
                <td class="gen_label"><label>Blog date: </label></td>
                <td><input class="gen_input" type="text" size="30" name="date" value="<?php if (isset($_GET['id'])) {
        echo $opened['date'];
    } ?>"/></td>
            </tr>
            <tr>
                <td class="gen_label"></td>
            </tr>
            <tr>
                <td colspan="2" class="gen_label"><label>Blog body: </label></td>
            </tr>
            <tr>
                <td colspan="2"><textarea id="page_body" name="body" cols="90" rows="24"><?php if (isset($_GET['id'])) {
        echo $opened['body'];
    } ?></textarea></td>
            </tr>
            <tr>
                <td colspan="2"><input class="gen_submit" type="submit" name="submit" value="Save Changes" /></td>
            </tr>

            <input type="hidden" name="submitted" value="1" />
            <input type="hidden" name="id" value="<?php if (isset($_GET['id'])) {
        echo $opened['id'];
    } ?>" />

        </table>

    </form>
<?php ?>
</div>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.