Saving data from dropdown

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

Re: [gversion] Saving data from dropdown

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

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

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

Re: [gversion] Saving data from dropdown

By Jason - October 30, 2012 - edited: October 30, 2012

Hi Greg,

Ah, this was a sneaky one. The issue here is that the word "condition" is a reserved word in mySQL. We can get around this by adding tick marks (`) around the field name like this:

$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'] ) ."'";


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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