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
Share on other sites

 

 

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.

 

 

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.