Jump to content


Photo

Error using NOW()


  • Please log in to reply
2 replies to this topic

#1 sgiandhu

sgiandhu
  • Validating
  • PipPip
  • Member
  • 13 posts
  • LocationVancouver, B.C. Canada

Posted 15 November 2005 - 04:54 PM

Hi there,

I am updating some information in a DB with a short form. However, inserting the date into the update field is being a bit of a trial.

partial code posted: the problem is evidently in this section

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formname")) {
  $updateSQL = sprintf("UPDATE tblName SET access=%s, uname=%s, password=%s, NOW() WHERE memberID=%s",

                       GetSQLValueString($_POST['access'], "int"),
                       GetSQLValueString($_POST['uname'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['info_update'], ''),
                       GetSQLValueString($_POST['memberID'], "int"));

mysql_select_db($database_name, $dbname);
  $Result1 = mysql_query($updateSQL, $dbname) or die(mysql_error());

I get an error message saying MySQL doesn't like my use of NOW() where it is in relation to the WHERE command...
Anyone able to correct me here?

Many thanks

J

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 November 2005 - 05:38 PM

you're not telling SQL what to update as NOW()... you have to assign it to a column just like all your other updates:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] tableName SET `[span style=\'color:blue;font-weight:bold\']update[/span]_time` = NOW() WHERE...
[!--sql2--][/div][!--sql3--]
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 sgiandhu

sgiandhu
  • Validating
  • PipPip
  • Member
  • 13 posts
  • LocationVancouver, B.C. Canada

Posted 15 November 2005 - 11:14 PM

[!--quoteo(post=318842:date=Nov 15 2005, 09:38 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Nov 15 2005, 09:38 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you're not telling SQL what to update as NOW()... you have to assign it to a column just like all your other updates:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] tableName SET `[span style=\'color:blue;font-weight:bold\']update[/span]_time` = NOW() WHERE... [!--sql2--][/div][!--sql3--]
[/quote]


Thank you .. how obvious! I did actually figure this out by looking at another post, however, having my thought process confirmed is very nice. I appreciate the help.


That's twice in 2 days I've had help here, so I'm off to make my donation.

Cheers and many thanks again

J




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users