Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Quotes in mysql update

    Code:
    mysql_query("UPDATE notice SET notice=\"$notice\"") or die('Server Error: ' . mysql_error());
    This query works fine when I put normal text, like "abcdefgjijklmnopqrstuvwxyx" and 12345678990" but when I use the quotes I get this error: Server 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 '"This site is under construction.""' at line 1. And its because of the quotes. How do you get around this, how do I fix this?

    Thanks,
    Jon W

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,437
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Use apostrophes.

    mysql_query("UPDATE notice SET notice='$notice'")

    If that causes problems becuz PHP doesn't allow substitution inside '...' then use string append instead of in place substitution. I'm not a PHP person, but I think you could do

    mysql_query("UPDATE notice SET notice='" . $notice . "'")

    No?

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Location
    Elkton, MD
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Escaping

    Go with-

    mysql_query("UPDATE notice SET notice='$notice'");

    This is the best practice. You might also consider encoding and decoding values-

    http://us3.php.net/manual/en/functio...ecialchars.php

    This will avoid the problem entirely. Good luck.

    Ranjit Viswakumar
    Professional Services Specialist
    HostMySite.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •