Saving data from dropdown

6 posts by 3 authors in: Forums > CMS Builder
Last Post: October 30, 2012   (RSS)

By gversion - October 29, 2012

Hello,

I have taken addForm.php and added some dropdown menus to it. The options for the dropdowns are being successfully pulled from the database using some other code I have found on the forum here:

https://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=67011

<?php
// This form requires: CMSB v2.04 Build 1
require_once "../cmsAdmin/lib/viewer_functions.php";
$tableName = 'listings';
$recordNum = null; // you must set either $recordNum or $preSaveTempId to null
$preSaveTempId = @$_REQUEST['preSaveTempId'] ? $_REQUEST['preSaveTempId'] : uniqid('x');
$errorsAndAlerts = '';

// get field options for Currency
$fieldname = 'currency';
$selectedValue = '';
$valuesAndLabels = getListOptions($tableName, $fieldname);
$optionsCurrency = getSelectOptions($selectedValue, array_keys($valuesAndLabels), array_values($valuesAndLabels));

// get field options for Condition
$fieldname = 'condition';
$selectedValue = '';
$valuesAndLabels = getListOptions($tableName, $fieldname);
$optionsCondition = getSelectOptions($selectedValue, array_keys($valuesAndLabels), array_values($valuesAndLabels));


However, I keep receiving this error message when I submit the form:

MySQL Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition = 'Good'' at line 7


I can get the form to save all the other fields but as soon as I try and save the options from the "condition" field I receive the error message.

Here is the code I am using to save the data to the database:

$query = "INSERT INTO `{$TABLE_PREFIX}$tableName` SET
createdDate = NOW(),
createdByUserNum = '" .intval( @$CURRENT_USER['num'] ). "',
updatedDate = NOW(),
updatedByUserNum = '" .intval( @$CURRENT_USER['num'] ). "',
product = '" .mysql_escape( $_REQUEST['product'] ). "',
condition = '" .mysql_escape( @$_REQUEST['condition'] ) ."'";



Can someone please explain what the problem is here?

Thank you,
Greg

Re: [gversion] Saving data from dropdown

By gregThomas - October 30, 2012

Hi Greg,

Would it be possible to post or attach the entire pages code?

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Saving data from dropdown

By gversion - October 30, 2012

Hi Greg,

Attached are the files.

Thanks,
Greg
Attachments:

tools.zip 3K

Re: [gversion] Saving data from dropdown

By Jason - October 30, 2012

Hi,

It would help if we could see the entire query that is being executed. Try making this change to your die() call:

mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error() . showme($query)) . "\n");

This will output your entire query on an error. Once we've fixed the issue, you can remove it. Can you please post the results so we can take a look?

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Saving data from dropdown

By gversion - October 30, 2012

Hi Jason,

Here are the results:

INSERT INTO `cms_listings` SET createdDate = NOW(), createdByUserNum = '0', updatedDate = NOW(), updatedByUserNum = '0', condition = 'Good'
MySQL Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition = 'Good'' at line 6


Thanks for the help.

Greg