SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove Commas before adding to DB

    I need to ensure no commas are saved in a particular MySQL table. Is there a way to do this within the database itself without using PHP code on the web server prior to the data being past to the DB? I was thinking perhaps a stored procedure (not sure if this is what they're called in MySQL). I would really appreciate any help on this.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    before adding data to the database, i sincerely hope your application code checks for and prevents sql injection

    that's where you can remove the commas as well
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point. The application is checking to prevent sql injections. I will begin there. Thanks for pointing me in the right direction.

  4. #4
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INSERT INTO tablex VALUES (REPLACE("mycomma,test text, haha", ",", " "));
    that should work I think.

    But yes, you should really clean the inputs before you get to this stage.


Bookmarks

Posting Permissions

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