MySQL Syntax Issue when updating expiresDate

5 posts by 3 authors in: Forums > CMS Builder
Last Post: December 20, 2011   (RSS)

Re: [gkornbluth] MySQL Syntax Issue when updating expiresDate

By Jason - December 19, 2011

Hi Jerry,

The problem you're having here is that there is no value in $_REQUEST['expiresDate'], since you probably don't have an "expiresDate" field in the form your submitting. If they are logged in successfully, you could use $CURRENT_USER to get the expires date.

Another approach is to just use the field name and increment whatever that value is by one year.

For example:

// UPDATE ONE YEAR FROM EXISTING EXPIRATION DATE
mysql_query("UPDATE `{$TABLE_PREFIX}accounts`
SET expiresDate = expiresDate + 'INTERVAL 1 YEAR' ,
WHERE password = '" . $_REQUEST['password'] . "'
AND username = '" . $_REQUEST['username'] . "'")
or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$userNum = mysql_insert_id();


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/

Re: [Jason] MySQL Syntax Issue when updating expiresDate

Hi Jason,

Thanks for this.

2 minor changes to get it to work.

I removed
1) the single quotes around INTERVAL 1 YEAR and
2) the comma after it since it's the last in the series (like you taught me).

Is removing the single quotes OK, or did I cause other issues that I haven't found yet?

Best,

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

Re: [gkornbluth] MySQL Syntax Issue when updating expiresDate

By Dave - December 20, 2011

Removing the single quotes is the way to do it.

Also, don't forget to escape your inputs:

WHERE password = '" . mysql_escape($_REQUEST['password']) . "'
AND username = '" . mysql_escape($_REQUEST['username']) . "'")

And if you only want to edit the current user I'd use $CURRENT_USER, but if you need to check the form input you'll need $_REQUEST.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] MySQL Syntax Issue when updating expiresDate

Oops, thanks for the reminder, Dave.

I do need to check the form in this case.

Best,

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