I am using query for joomla.
$query = "INSERT INTO '#__demo'( 'id', 'fname', 'mname', 'lname' ) VALUES ( '$val', '$post['fname']', '$post['Mname']', '$post['Lname']' );";
It is giving error
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
There are two mistakes on your query.
You haven't escaped your quotes in
$_POST
values.You are using single quotes
'
to represent tables and field names.Now after removing all such problems. You query becomes:
For inserting the data you can use this format also in joomla 2.5 :
stdClass is a php base class from which all other classes are extended.
'id' is the name for your primary key for the connected table.
You can use a more formatted way of writing insert query
You can get the reference from here
https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase