OMFG SQL WTF BBQ

Dude. SOMEBODY please tell me what’s wrong with this statement:

$query="UPDATE eventTable SET date='$ed_eventDate',
   eventTitle='$ed_eventTitle', location='$ed_location', 
   desc='$ed_desc' WHERE eventID=$ed_eventID";

I’ve been fighting with this one line for over an hour, trying to get the damn LSM calendar to update, and it keeps telling me I have a syntax error. I know it’s gotta be something small and stupid, but fuck if I can tell what it is.

If you know what’s wrong and you’d like to share, or if you might know but need to see the code around this to be sure, please share your infinite wisdom with me.

I’m getting that old frustrated “Come on, Diana, it’s time for a break / No, I’ve almost got it, I don’t want to stop now” feeling that I used to get when I was learning attempting to learn Macromedia Lingo back in the day. Except this time, I’m not going to stay up all night and watch Weird Al on MTV or Futurama on… whatever channel it was on. I’m going to go to bed instead.

Update, 8/24/2005 8:55pm: It was my variable names! I used “date” and “desc” as variables, and they’re reserved words. Once I changed my variable names, the query worked in MyPHPAdmin. I’m still working on getting the actual page to update, as I have several variable names to correct…

12 thoughts on OMFG SQL WTF BBQ

Comments are closed.

  1. w/o the full code, i only notice that the single quotes are missing from around your $ed_eventID variable.

    keep in mind it’s late and there maybe other problems since i can’t see straight… ha i made a funny!

  2. i’m assuming eventid is an integer, though, and shouldnt need single quotes?

    i’ll run a similar query through query analyzer when i get to work 😛

  3. i tried it both ways, with and without single quotes. around everything. and, yes, eventID is an integer.

    these variables were passed from a POST operation, and i assigned my variables like:

    $ed_eventTitle=$_POST[‘ed_eventTitle];

    in the confirmation code, after the UPDATE, i plug in the edited variables ($ed_eventTitle in $ed_location has been successfully updated), and those take, but it never gets to the db.

    i can post the rest of the code tonight when i get home from work, assuming neither of you have a major brainstorm before then. 🙂 thanks, girls.

  4. Do you get a specific error, or does it just say “syntax error”?

    i know MSSQL (and yes, i know this isnt MSSQL) gets all sorts of goofy if your date field is of type datetime and not string and you send it goofy things.

    can you plug values into this query and try to run it? like:
    $query=”UPDATE eventTable SET date=’05/10/1979′,
    eventTitle=’test title’, location=’diana’s basement’,
    desc=’sheryl and diana go bananas with too much monkeys’ WHERE eventID=4″;

  5. also, are there single quotes in any of your post variables? like in the description is there an “it’s” or “they’re” or anything? sometimes you have to do yourself a little ‘sed’…

    i’m not great with PHP development but those are the things i’ve found to screw up sql queries you build as a string.

  6. i did try using the mysql_escape… um… whatever the crap it was, on my description field. i need to research it some more, but it’s supposed to escape out the evil characters.

    lemme go log in and get you the exact error it throws.

    *opens new window and putzes*

    i have it echoing mysql_error() if no result, and it says, “SQL 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 ‘desc=’Leave housing site by 10:00AM.’ WHERE eventID=3′ at line ”

    i hadn’t thought of the date thing. i’ll have to look into that, too. good idea.

  7. hrm well yeah… usually at this point i plug in some literal sample data like sheryl suggested into a phpmyadmin query and then click generate php code. i then go back to my own php page and start substituting variables one by one into the code until i get an error.

    [crosses her fingers for you]

  8. sounds like a plan. when i get home, i’ll log into phpmyadmin and start feeding it stuff and see where i can go from there.

    i’ll keep you updated. whee!

  9. i knew “date” was in MSSQL but i wasnt sure about MySQL, so i just kept my mouth shut. o well 😀

    as for “desc” – wtf, half of my description variables that arent “description” are “desc” 😀 wierd!

  10. that was why i used ‘desc’ in the first place: you used it when you were helping me out and giving me examples. but plugging stuff into phpmyadmin finally got the solution through my thick skull.

    “why are two of my variables showing up in capital letters and in a different color…? D’oh!”