October 11, 2012
How to use Insert into query for joomla 2.5?
Question by Durgesh Sonawane
Iam 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
Answer by Starx
There are two mistakes on your query.
-
You haven’t escaped your quotes in
$_POST
values.'$post['fname']' // ^ here and other places
-
You are using single quotes
'
to represent tables and field names... INTO '#__demo'( .. // ^ here and other places
Now after removing all such problems. You query becomes:
$query = "INSERT INTO `#__demo` ( `id`, `fname`, `mname`, `lname` ) VALUES ( '$val', '$post[fname]', '$post[Mname]', '$post[Lname]' );";