Jump to content

why does my get variable get lost?!


jimmi8

Recommended Posts

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]<?php
session_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>


 <?php

if (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"/>

<?php
include ('footer.inc');
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31429-why-does-my-get-variable-get-lost/
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.