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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.