Skip to content
Advertisement

Only variables should be passed by reference when entering a longer text

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();
        $project->set_title($_POST['title']);
        $project->set_description($_POST['description']);
        $project->set_imgPath($uploadfile);

        $project->insert($project);

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement