Jump to content

Brackets


gautamz07

Recommended Posts

function send_msg($sender , $message){

        if(!empty($sender) && !empty($message)){

                $sender = mysql_real_escape_string($sender);
                $message= mysql_real_escape_string($message);

                $query = "INSERT INTO  `chat`.`chat` VALUES (null , '{$sender}' , '$message')";    // Difficulty on THIS LINE !!!!

                if($run = mysql_query($query)){
                        return true;
                }else{
                        return false;
                }
        }
 

 

 

 

 

 


why is '{$sender}' given the curley brakets ????? and why is message not given the same brackets ? 

also why is this function used ? i.e. mysql_real_escape_string , i know what it does , but is it to prevent SQL injection.

 

Link to comment
https://forums.phpfreaks.com/topic/288693-brackets/
Share on other sites

  Quote

 

 

why is '{$sender}' given the curley brakets ????? and why is message not given the same brackets ? 

No idea why, but variables in a double quoted string can be wrapped in curly braces, usually they are only required for more complex variables names such as arrays/objects, example

echo "Welcome, {$_SESSION['username']}";

It just explicitly points out to PHP the start/end of a variable name.

 

  Quote

 

 

also why is this function used ? i.e. mysql_real_escape_string , i know what it does , but is it to prevent SQL injection.

You've just contradicted yourself  :-\ If you knew what it does then you wouldn't need to ask that question.

Link to comment
https://forums.phpfreaks.com/topic/288693-brackets/#findComment-1480509
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.