jimmi8 Posted December 20, 2006 Share Posted December 20, 2006 Hi,Im having a problem with this simple script. Its purpose is to allow me to edit a blog post. The problem im having is when i click submit after ive made changes i get an error saying mysql_fetch_array is not a valid resource.Now the script works and the sql definatley works as the text to be edited it originally put in the fields for editing so i know at some point the array is a valid resource! The problem comes when submit is pressed. The id of the blog seems to be lost at this point as well as the error message occuring.Im sorry to post here with this as i know its something really stupid but ive looked at it again and again over the last few days, tried to methodically find out where the problem is but i havent found a solution.I wouls really appreciate any suggestions! Heres the code:[code]<?phpsession_start();if (!isset($_SESSION['first_name'])) { header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "index.php"); exit(); // Quit the script.}include ('header.inc');require_once ('mysql_connect.php');if(isset($_GET['blog_id'])) {$blog_id = $_GET['blog_id'];}else {$blog_id = NULL;echo 'Please specify a section';} $sql = "SELECT * FROM entries WHERE blog_id = $blog_id"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $title = $row['title']; $body = $row['body']; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label> Edit Title </label><input type="text" class="text" size="50" name="title" maxlength="200" value="<?php echo $title; ?>" /> <label> Edit Body </label><textarea name="body" type="text" rows="20" columns"3" maxlength="800" value=""><?php echo $body; ?></textarea> <input type="hidden" name="blog_id" value="<?php echo $blog_id; ?>"> <p><label> Edit category</label><select name="category" value="<?php echo $cat; ?>"> </form> <?phpif (isset($_POST['submitedit'])) {if($title && $body) { //update the database with edited data $formdata= "title = '$title', body = '$body'"; $sql = "UPDATE entries SET $formdata WHERE blog_id = $blog_id"; $result = mysql_query($sql); $title = $row['title']; $body = $row['body'];}else { echo 'please fill out form fields';}}?><input type="submit" name="submitedit" class="submit" value="SUBMIT"/><?phpinclude ('footer.inc');?> [/code] Link to comment https://forums.phpfreaks.com/topic/31429-why-does-my-get-variable-get-lost/ Share on other sites More sharing options...
esukf Posted December 21, 2006 Share Posted December 21, 2006 You're checking $_GET while your form is using the POST method. Use $_POST.[code]<?phpif(isset($_POST['blog_id'])) {$blog_id = $_POST['blog_id'];}else {$blog_id = NULL;echo 'Please specify a section';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31429-why-does-my-get-variable-get-lost/#findComment-145535 Share on other sites More sharing options...
JasonLewis Posted December 21, 2006 Share Posted December 21, 2006 try addingf this like above $sql... below $formdate...[code=php:0]$blog_id = $_POST['blog_id'];[/code]@esukf: The OP may be selecting the blog id for the first part through the url... Link to comment https://forums.phpfreaks.com/topic/31429-why-does-my-get-variable-get-lost/#findComment-145536 Share on other sites More sharing options...
esukf Posted December 21, 2006 Share Posted December 21, 2006 On second look, projectfear is correct. Link to comment https://forums.phpfreaks.com/topic/31429-why-does-my-get-variable-get-lost/#findComment-145567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.