How do I insert text in an sql database using the new Jdatabase system?

91 Views Asked by At

I have been struggling with this for the entire morning. Here is the code (to be precise the $message variable is defined with $message= htmlspecialchars($_GET["message"]); :

 if (!$user->guest)
{
    if (!$message=="")
    { 
    echo $message;
    $query = $db->getQuery(true);
    $query->INSERT('#__soccermanager_chats (userid,message,eventid) VALUES ('.$user->id.','.$message.','.$gameid.')');
    $db->setQuery($query);
    $db->query();
    }
}

Basically all it does is adding a message to a message board. The only thing is that it's only working with figures and not letters.

So I have been looking to my mysql table and the message field type is varchar(255). And when I do a manuel query from eskuel it works!

1

There are 1 best solutions below

1
AudioBubble On BEST ANSWER

In Php u can assign variable using "$variable name" for Example $number=1(integer)$string="a"(String)$float=1.23(float)
u want to insert number through variable u can use '.$number.' and if u want to insert String then u can use '".$string."'. $query->INSERT('#__soccer manager_chats (user id,message,event id) VALUES ('.$user->id.','".$message."','.$game id.')');