Jump to content

[SOLVED] Unable to UPDATE Post


Altec

Recommended Posts

Here is my current code:

 

            case 'edit':
                if(isset($_GET['postid'])) {
                    mysql_connect('localhost','rawr','rawr');
                    mysql_select_db('rawr');
                    $postid = (int) clean($_GET['postid']);
                    if(empty($postid)) {
                        echo '<p>Specified post id is empty or invalid.</p>';
                    } else {
                        $result = mysql_query("SELECT * FROM `blog` WHERE `id` = '{$postid}' LIMIT 0,1");
                        if(!$result) {
                            echo '<p>Error: '.mysql_error().'</p>';
                        } else {
                            $row = mysql_fetch_array($result);
                            $title = str_replace('"','\'',$row['title']);
                            $content = str_replace('<br />','',$row['content']);
                        ?>
<p>Use the form below to edit blog post #<?php echo $row['id']; ?>.</p>
<fieldset>
    <legend>Edit Blog Post #<?php echo $row['id']; ?></legend>
    <form action="./edit_blog.php" method="post">
        <input type="hidden" name="postid" value="<?php echo $postid; ?>" />
        <label for="title">Title</label><input type="text" id="title" name="title" size="60" value="<?php echo $title; ?>" /><br /><br />
        <label for="content">Content</label><textarea id="content" name="content" cols="70" rows="15"><?php echo $content; ?></textarea><br /><br />
        <input type="submit" name="submit" value="Edit Blog" class="button" /> <input type="submit" name="delete" value="Delete Blog" /> <input type="button" value="Cancel" onclick="javascript:window.location='./index.php'" />
    </form>
</fieldset>
                        <?php
                        }
                    }
                } else {
                    mysql_connect('localhost','rawr','rawr');
                    mysql_select_db('rawr');
                    $result = mysql_query("SELECT * FROM `blog` ORDER BY `timestamp` DESC");
                    if(!$result) {
                        echo '<p>Error: '.mysql_error().'</p>';
                    } else {
                        echo '<p>Select the blog post you want to edit or delete from the list below.</p>'."\n";
                        echo '<ul>'."\n";
                        while($row = mysql_fetch_array($result)) {
                            echo '<li><a href="./?type=blog&action=edit&postid='.$row['id'].'">'.$row['title'].'</a></li>'."\n";
                        }
                        echo '</ul>';
                    }
                }
            break;

 

The actual update script:

if($_SERVER['REQUEST_METHOD'] == "POST") {
    if(isset($_POST['submit'])) {
        mysql_connect('localhost','rawr','rawr');
        mysql_select_db('rawr');
        foreach($_POST as $name => $value) {
            $d[$name] = clean($value,'mysql');
            if(empty($d[$name])) {
                $error = 'You left the field "'.$name.'" blank.';
            }
        }
        if(isset($error)) {
            echo '<p>'.$error.'</p>';
        } else {
            $d['content'] = nl2br($d['content']);
            $query = "UPDATE `blog` SET `title`='{$d['title']}',`content`='{$d['content']}' WHERE `id`='{$d['postid']}' LIMIT 1";
            if(!mysql_query($query)) {
                echo 'Error: '.mysql_error();
            } else {
                echo '<br /><span><strong>Blog post updated successfully.</strong><br /><br />[ <a href="./index.php">Back to ACP</a> ]</span>';
            }
        }
    }
}

 

The post never updates, but I don't get any errors. What's going on?

Link to comment
https://forums.phpfreaks.com/topic/155688-solved-unable-to-update-post/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.