php – Only variables should be passed by reference when entering a longer text-ThrowExceptions

Exception or error:

I have that strange error that appears when I try to enter a longer text but it works with a simple sentence, this below is my code:

function insert($project)
    if (!empty($project->get_title()) && !empty($project->get_description()) && !empty($project->get_imgPath())) {
        include 'openConnection.php';

        // prepare and bind
        $stmt = $dbLink->prepare("INSERT INTO projects (title, description, imgPath) VALUES (?,?,?)");
        $stmt->bind_param("sss", $project->get_title(), $project->get_description(), $project->get_imgPath());

        // execute
        if ($stmt->execute()) {
            return $stmt->insert_id;
        } else {
            $this->addError("Insert failed");
            return false;
    } else {
        $this->addError("All fields must be provided");

This one below calls the insert method above passing the project:

$project = new Project();

How to solve:

I think the error might be that your database has a limit on how many characters the string can be. If you try to insert a string that is longer than the limit, your database may give you an error and not accept the row. I would recommend looking at the table structure and see if that column has a character limit specified.

Leave a Reply

Your email address will not be published. Required fields are marked *