SQL Syntax error

6 posts by 3 authors in: Forums > CMS Builder
Last Post: December 21, 2022   (RSS)

By pgplast - November 30, 2022

I have started getting an error from a SQL insert in a plugin I wrote:

$query = "INSERT INTO cms__accesslist SET
userNum = '".$user_num."',
tableName = 'all',
accessLevel = '1',
maxRecords   = '',
randomSaveId = '123456789' ";
mysqli()->query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysqli()->error) . "\n");

The error references the need to check for correct syntax around ''" and the randomSaveId value.

Can anyone se ewhat the culprit is? This is the same syntax I use in many other areas.

Thanks.

By Dave - December 7, 2022

Hi phplast, 

Did you get this resolved?  If not, try printing out the query with: echo $query;

It's a lot easier to spot errors in the generated SQL code.

Hope that helps, 

Dave Edis - Senior Developer
interactivetools.com

By pgplast - December 16, 2022

Resolved as mentioned via email.

Thanks.

By pgplast - December 17, 2022

For some reason I failed to determine, the syntax I posted earlier didn.t work.

However, using the below instead, did.

mysql_insert('_accesslist', array(
'userNum' => $user_num,
'tableName' => 'apply_for_cme',
'accessLevel' => '6',
'maxRecords' => '1000', // max listings allowed
'randomSaveId' => '123456789', /
));

By gkornbluth - December 21, 2022

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php