0

I am in the process of developing a forum with PHP and MySQL. I got stuck in a problem that i have never came up with before. The problem occurs when I am invoking a method to edit a forum post.

I have a object class to handle behaviors of a post. And I am trying to make the forum SEO friendly too, therefore I am using Unique URLs to identify posts as a experiment. If I have made security holes, please be kind enough to point them out, too (thank you!).

I will copy only the required parts of the code.

This is where i invoke the method

$url = $_GET['url'];
$posts->editForumPost($heading, $desc, $catetgory, $username, $tags, $url);

And to be sure if its not an array i print_r($url) which gives me the correct url sent in the address. I am familiar when I print_r an array, it says that it is an array and gives the indices and their values too. Its not like that in this case.

So in the editForumPost() function I call another function like this

$post = $this->getPostDetails($url);

take note here, that I am using this same function to get the values of the post to print it to display to the user. and I don't have a problem there, But when i call the function inside the editForumPost() function I get a

Array to string conversion in blah blah

I can't think of a reason why this happens. So then again i changed my functions to run in post_ids instead of urls, same problem happens for some reason.

I will post the full code of the functions and invoking places if anyone requests.

EDIT:

public function getPostDetails($url)
        {
            $query = $this->db->prepare("SELECT `heading`,`post_id`,`category`, `description`, `username`, `category`,`post_time` FROM `forum` WHERE `friendly_url` = ? LIMIT 1");
            $query->bindValue(1,$url);

            try
            {
                $query->execute();
            }
            catch(PDOException $e)
            {
                die($e->getMessage());
            }

            return $query->fetch();
        }
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Bhashithe
  • 122
  • 2
  • 14
  • If you sure `$this->getPostDetails($url);` giving you error then put dose of that function thanks. it will help you to get solution quickly. – Alive to die - Anant May 26 '15 at 14:15
  • @anantkumarsingh I have added the function – Bhashithe May 26 '15 at 14:44
  • point out the line where error occur? – Alive to die - Anant May 26 '15 at 14:50
  • $query->bindValue(1,$url); <= this line; array to string conversion – Bhashithe May 26 '15 at 15:00
  • Check link http://stackoverflow.com/questions/22154246/pdo-prepare-with-bindvalue-and-like and change your query like question first code. – Alive to die - Anant May 26 '15 at 15:08
  • I think the fetch() function works even without that fetch style. I know this since i haven't used that variable in any of my other functions. Still they work! As I think there should be a problem with how I call my function. or otherwise something else that i don't see – Bhashithe May 26 '15 at 15:33
  • 1
    We cannot debug this for you. The error is clear. We do not see all the code and all the steps that are happening and cannot confirm what your variable actually is nor can we trace what's happening to it. You need to debug more. `var_dump` your variable every step of the way and figure out where it turns into an array. – deceze May 26 '15 at 15:53
  • I will do that and get back to you @deceze – Bhashithe May 26 '15 at 17:29

0 Answers0