galvin Posted January 4, 2009 Share Posted January 4, 2009 Maybe this isn't enough info for this question to be answered, but I'll take a shot anyway. I have the following MySQL query... $query = "INSERT INTO captions ( cardfile ) VALUES ('" . $_SESSION['card1'] . "') WHERE orderID = " . $_SESSION['orderID'] . " AND card = 1"; ...and every time it runs, I get "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 'WHERE orderID = X AND card = 1' at line 4" It's pulling in the proper value for orderID (it's always a number, I just put an X above) and card, but it keeps giving this error. Do I have a problem with an extra (or missing) apostrophe or something? Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/ Share on other sites More sharing options...
jonsjava Posted January 4, 2009 Share Posted January 4, 2009 INSERT is for new data. ALTER TABLE changes existing data. it's used like this: "ALTER TABLE `captions` SET `table_row`='new_data' WHERE `table_row2` = 'check_against_data' AND `card`=1"; Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/#findComment-729345 Share on other sites More sharing options...
revraz Posted January 4, 2009 Share Posted January 4, 2009 echo $query and check it. Failing since you use a WHERE with INSERT Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/#findComment-729346 Share on other sites More sharing options...
revraz Posted January 4, 2009 Share Posted January 4, 2009 I think you mean UPDATE and not ALTER TABLE. INSERT is for new data. ALTER TABLE changes existing data. it's used like this: "ALTER TABLE `captions` SET `table_row`='new_data' WHERE `table_row2` = 'check_against_data' AND `card`=1"; Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/#findComment-729347 Share on other sites More sharing options...
galvin Posted January 4, 2009 Author Share Posted January 4, 2009 Jonsjava, I was incorrectly using INSERT, like you said, so thank you. And revraz, all I needed was UPDATE, like you said. That did the trick just fine for my purposes. Thanks to both of you!!! Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/#findComment-729354 Share on other sites More sharing options...
jonsjava Posted January 4, 2009 Share Posted January 4, 2009 I think you mean UPDATE and not ALTER TABLE. INSERT is for new data. ALTER TABLE changes existing data. it's used like this: "ALTER TABLE `captions` SET `table_row`='new_data' WHERE `table_row2` = 'check_against_data' AND `card`=1"; way too tired. just woke up when I posted that. Link to comment https://forums.phpfreaks.com/topic/139428-solved-sql-syntax/#findComment-729366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.