Altec Posted April 26, 2009 Share Posted April 26, 2009 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 More sharing options...
jackpf Posted April 26, 2009 Share Posted April 26, 2009 Put or die(mysql_error()); after every query or mysql connection. Link to comment https://forums.phpfreaks.com/topic/155688-solved-unable-to-update-post/#findComment-819492 Share on other sites More sharing options...
Altec Posted April 26, 2009 Author Share Posted April 26, 2009 I did so and they magically started updating. Link to comment https://forums.phpfreaks.com/topic/155688-solved-unable-to-update-post/#findComment-819869 Share on other sites More sharing options...
jackpf Posted April 27, 2009 Share Posted April 27, 2009 Hmm...they shouldn't just start updating, you should see some errors or something, and then fix them. And then it should start magically updating. But meh, good job. Link to comment https://forums.phpfreaks.com/topic/155688-solved-unable-to-update-post/#findComment-820119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.