tags:

views:

49

answers:

4
$sql = "UPDATE tblprofile SET name = '$membername' ,
                                        f_h_name = '$fathername', 
                                        maritalS = '$mstatus' , 
                                        dob = '$dob' , 
                                        occupation = '$occupation' , 
                                        nominee = '$nominee' , 
                                        address1 = '$address1' , 
                                        address2 = '$address2',
                                        city = '$city',
                                        district = '$district',
                                        state = '$state',
                                        pin = '$areapin',
                                        mobile = '$mobileno',
                                        email = '$email',
                                        PANno = '$panno',
                                        bankname = '$bankname',
                                        branch = '$branch',
                                        accountno = '$accountno'
                                        WHERE userId = '$_SESSION['UserId']' "; //line 212
    if(mysql_query($sql))
    {
        echo "Updation Done.";
    }

Error comes in browser : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\303\saveEditProfile.php on line 212

+2  A: 

Your variable reference $_SESSION['UserId'] inside the double quoted string is not allowed. You either need to write $_SESSION[UserId] (without quoting the key):

"… WHERE userId = '$_SESSION[UserId]' "

Or use the curly brace syntax {$_SESSION['UserId']}:

"… WHERE userId = '{$_SESSION['UserId']}' "

But I rather suggest you to use a parameterized function to build your query (like sprintf) or Prepared Statements so that you can protect yourself agains SQL Injections as well.

Gumbo
what are SQL Injections?
nectar
@nectar: http://en.wikipedia.org/wiki/Sql_injection
Felix Kling
@nectar: An SQL Injection is a code injection attack where the attacker uses malicious input that, if put into the SQL statement, results in a SQL statement that behaves differently than the author intended. Take a look at the Wikipedia article at http://en.wikipedia.org/wiki/SQL_injection to see some details.
Gumbo
+1  A: 

Try this:

$sql = "UPDATE tblprofile SET name = '$membername' ,
                                    f_h_name = '$fathername', 
                                    maritalS = '$mstatus' , 
                                    dob = '$dob' , 
                                    occupation = '$occupation' , 
                                    nominee = '$nominee' , 
                                    address1 = '$address1' , 
                                    address2 = '$address2',
                                    city = '$city',
                                    district = '$district',
                                    state = '$state',
                                    pin = '$areapin',
                                    mobile = '$mobileno',
                                    email = '$email',
                                    PANno = '$panno',
                                    bankname = '$bankname',
                                    branch = '$branch',
                                    accountno = '$accountno'
                                    WHERE userId = '{$_SESSION['UserId']}' "; //line 212

I strongly suggest you have a look at php.net/sprintf, e.g.:

$sql = sprintf("SELECT id FROM table WHERE name = '%s'", $name);
halfdan
A: 

Fast hack do get this working is to remove single qoutes in last SQL query line, like this:

WHERE userId = '$_SESSION[UserId]' ";
retro
+3  A: 

Try changing to this:

$_SESSION[UserId]
Ardman