Forum Moderators: open

Message Too Old, No Replies

Can't find the error in syntax.

         

jbearnolimits

12:54 pm on Sep 15, 2022 (gmt 0)

Top Contributors Of The Month



I need a little help figuring this error out.

Error: UPDATE `Contacts` SET `FirstName`=[lee],`LastName`=[fee],`SpouseFirstName`=[],`SpouseLastName`=[],`Phone`=[951-555-5555],`SpousePhone`=[],`Email`=[],`SpouseEmail`=[],`HomeAddress`=[],`HomeCity`=[],`HomeState`=[],`HomeZip`=[],`MailingAddress`=[],`MailingCity`=[],`MailingState`=[],`MailingZip`=[],`Type`=[Agents/Offices],`Source`=[],`Notes`=[] WHERE id = 1
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 '[lee],`LastName`=[fee],`SpouseFirstName`=[],`SpouseLastName`=[],`Phone`=[951' at line 1

$sql = "UPDATE `Contacts` SET `FirstName`=[$FirstName],`LastName`=[$LastName],`SpouseFirstName`=[$SpouseFirstName],`SpouseLastName`=[$SpouseLastName],`Phone`=[$Phone],`SpousePhone`=[$SpousePhone],`Email`=[$Email],`SpouseEmail`=[$SpouseEmail],`HomeAddress`=[$HomeAddress],`HomeCity`=[$HomeCity],`HomeState`=[$HomeState],`HomeZip`=[$HomeZip],`MailingAddress`=[$MailingAddress],`MailingCity`=[$MailingCity],`MailingState`=[$MailingState],`MailingZip`=[$MailingZip],`Type`=[$Type],`Source`=[$Source],`Notes`=[$Notes] WHERE id = $id";

jbearnolimits

2:30 am on Sep 16, 2022 (gmt 0)

Top Contributors Of The Month



I discovered the error. So I am now able to update the database. BUT I used the same code (only added the creation date and removed the id) for the creation of a profile. For some reason this syntax works for UPDATE Contacts SET... but it is giving this error when trying to INSERT INTO Contacts:

Error: INSERT INTO Contacts FirstName = 'fhndh', LastName = 'hnm', SpouseFirstName = 'fhdm', SpouseLastName = 'hfdm', Phone = 'hfm', SpousePhone = 'fhm', Email = '', SpouseEmail = '', HomeAddress = '', HomeCity = '', HomeState = '', HomeZip = '', MailingAddress = '', MailingCity = '', MailingState = '', MailingZip = '', Type = 'Agents/Offices', Source = 'hfdm', Notes = '', CreationDate = '09-16-2022'
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 'FirstName = 'fhndh', LastName = 'hnm', SpouseFirstName = 'fhdm', SpouseLastName ' at line 1

jbearnolimits

3:09 am on Sep 16, 2022 (gmt 0)

Top Contributors Of The Month



I really wish I could delete these posts. I seem to find the answers before anyone can reply and it feels like I'm just taking up space. Anyway, I have discovered that for some reason a different way of writing it is needed for the different commands. One syntax for UPDATE and another for INSERT.

not2easy

3:15 am on Sep 16, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Don't worry about deleting posts when you have found the answer. Next month or a year from now, someone will appreciate that you spotted the solution in record time and answered their problem too. It may be just what someone else is struggling with. It helps a lot when others share their solutions.

jbearnolimits

5:56 am on Sep 16, 2022 (gmt 0)

Top Contributors Of The Month



That's why I share the solution instead of just saying "Nevermind, I got it." I hate it when I'm searching for answers to a problem someone else posted that they had too and they just say they got it without saying what they got lol. So I try to keep that in mind when I figure things out.