Jump to content

[SOLVED] For the life of me... Update query problem!


DBookatay

Recommended Posts

I've been struggling with (what I thought was) a simple query, but I keep getting this 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 '( logo, last_updated ) VALUES ( 'Default', '2008-19-11' )' at line 1

 

The query is:

if ($_POST['edit']) {

  $logo = $_POST['logo'];
  $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1'];

mysql_query("
UPDATE Website SET (logo, last_updated) 
VALUES ('$logo', '$updated')"
)or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=edit.php?category=Logos\">";}

 

The query works with just the "logo", but once I add the "updated" values I throw an error. I've tried with the DB field as date and as varchar and continue to get the error.

 

Anyone have any ideas?

something like

 

if ($_POST['edit']) {

  $logo = $_POST['logo'];
  $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1'];
$query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')";
mysql_query($query)or die(mysql_error());}

something like

 

if ($_POST['edit']) {

  $logo = $_POST['logo'];
  $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1'];
$query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')";
mysql_query($query)or die(mysql_error());}

 

Copied and pasted your code exactly and got this 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 '(logo, last_updated) VALUES ('Default', '2008-19-11')' at line 1

oops, I'm sorry.

 

if ($_POST['edit']) {

  $logo = $_POST['logo'];
  $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1'];
$query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')";
echo $query;
mysql_query($query)or die(mysql_error());}

 

though the error message kind of shows us what we need to know...

use tis but on a side note i thought you needed a where statement to edit im kinda newish with update so please correct me if im wrong

but this code below works for me

 

        $query = "UPDATE Website SET  logo = '$logo', last_updated = '$updated'";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


echo $query;

Ok, this is what I got:

UPDATE Website (logo, last_updated) VALUES ('Default', '2008-19-11')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 '(logo, last_updated) VALUES ('Default', '2008-19-11')' at line 1

http://www.tizag.com/mysqlTutorial/mysqlupdate.php

 

your telling it to update but not what to update

 

that link is a tutorial on update but my code will work if you add a where cluase

do you have an id on this table or anything you can reference as the where ?

      $query = "UPDATE Website SET  logo = '$logo', last_updated = '$updated' WHERE FIELDNAME='SOMETHING'";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
      

echo $query;

 

haha np on the head slap its the whole extra set of eyes that code looked so different from mine i was like whao and noticed that it didnt have one

When you edit a column you have to set a WHERE param.

 

UPDATE Website SET  logo = '$logo', last_updated = '$updated' WHERE something='something'

 

thanks, dropfaith, for slapping the back of my head on that one.

 

WOW, I feel like a REAL iddiot!!!

 

Thanks for all the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.