Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Bremgarten, Switzerland
    Posts
    17
    Rep Power
    0
    Hi everybody,

    I insert text into a MySQL Database using a TEXT field.

    PHP syntax is:

    $query = "INSERT INTO data (text_field) VALUES('$text_field')";

    The problem is, when the user has an apostroph (like "friggin' cool") in the text, MySQL misinterprets it, and the query is invalid. Is there a PHP function that formats the that input so it can be entered into the database?

    Thanks,
    Alex Suzuki
  2. #2
  3. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    I guess u don't like reading manuals eey..

    use AddSlashes($str)
    and never ever ask again

    ------------------
    Greetings lewi
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    9
    Rep Power
    0
    Hey lewi, why don't you not be a jerk, eey? Or is there no manual on that?

    Dogg
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    Ah, now i get it
    lol

    u can't stand a comment



    ------------------
    Greetings lewi
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    I don't think Lewi is being a jerk. He's trying to teach people how to learn to program.

    asuzuki: you want to know how to write a string to a database? How about chapter 7 of the MySQL manual:
    7 MySQL Language Reference

    7.1 Literals: How to Write Strings and Numbers

    7.1.1 Strings

    That might give you an idea of why you need addslashes(), instead of just knowing that if you do it that way, it works.

    Dogg: That's why it's important that you tell people like this to read the manual. He would of gone on using addslashes(), found out it worked, but had no idea why it worked. You don't learn how to program by writing a bunch of code you don't know, then get other people to debug it for you, and then call yourself a programmer. That's how you become a manager, not a programmer.

    Hopefully I've made myself clear...

    ---John Holmes...

    Questions like this are why I even added a signature.

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  10. #6
  11. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    thnx for backup, and you r absolutely right

    just trying to learn people how to program.
    but i't not that those people don't have to think
    by theirself, and ask first instead of thinking and
    trying first

    if u want to learn how to program u should learn how
    to read the manual first, and how to find information
    in that manual.

    some suggestions:
    1st read the manual entirely (not every word, but some parts
    all over the place)
    u don't have to memorise everything, almost every answer i gave on
    this forum was created by someone else, i just found the answer
    by looking at the right place..
    at php.net there r even user notes on how to use the functions, it
    can't be much easier..
    well ok, u can ask people first (but u won't learn from that)

    i don't want to be like a jerk, and even in this case i tried NOT
    to be like a jerk

    ------------------
    Greetings lewi
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Bremgarten, Switzerland
    Posts
    17
    Rep Power
    0
    hey,

    sorry for having wasted your time, I was just probably too lazy to lookup a manual or a book. But don't worry, I will keep asking questions when I need a fast answer...

    asuzuki
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    58
    Rep Power
    15
    Lewi, you really are a jerk aren't you. :-)


    "1st read the manual entirely" (!!)
    The PDF Manual I use is 723 pages long. Do I need to explain why your argument fails?

    "if u want to learn how to program u should learn how to read the manual first"
    Yeah. That's cool. You said "how to", which is how to search, browse, etc.


    If you don't have much knowledge of scripting (ohh, PHP is not programming, it's scripting by default) or DB admin, then it's going to be very difficult to know what you are lookin for.
    "Hmm, that SQL doesn't work, perhaps I should configure mySQL", the newbie thinks.

    Bottom line. Be rude as you have all the right be to people who are lazy and not searching the forums or the manual, but be kind to people who don't even know what they're looking for.

    Cheers, Peter

    ------------------

    peterbe.com
  16. #9
  17. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    lol

    1st yeah, read it... but i didn't say read it
    all.. just look ad the headings etc.. and read parts of it.

    2d.. i guess u misunderstand me, ..ah well

    3d your absolutely right.. it is a scripting language.. sort of programming still, but ok, and if u can install php, then little things shouldn't be a problem

    and bottom line..
    i DIDN'T intended to be rude, and i won't try to be also, unless someone is rude to me

    nice comments though discussion although



    ------------------
    Greetings lewi
  18. #10
  19. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    I would like to say that because im dutch, and english is not my foreign language, it's sometimes hard to even understand the manual!!

    And i don't find the php manual complete!!
    look for fsockopen! after reading the manual about that, i didn't understand exactly what fsockopen does!! what is easy for you isn't easy for other people.


    ------------------
    Until next time, I'll Remain!!
    Quote the Dokus:"NeverMore!"
  20. #11
  21. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    Ik ben ook nederlands
    (meaning: i'm dutch to)

    But heey, i understand it..
    and offcourse there are some..erm
    lot's off missing parts, .. and then any forum would be very handy

    ------------------
    Greetings lewi
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Bremgarten, Switzerland
    Posts
    17
    Rep Power
    0
    I am Swiss and I have actually no problems reading an english manual. Look, the point is that we have been "wasting" a considerable ammount of time just discussing this issue, despite the actual issue (my question) being solved in what, a few seconds of your time?

    -asuzuki
  24. #13
  25. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    Yeah, about 0.30 seconds

    but the discussion is going to be much longer
    lol

    ------------------
    Greetings lewi
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Bremgarten, Switzerland
    Posts
    17
    Rep Power
    0
    Well, that's the point. You had little to no problems helping me and it took you basically no time and you made somebody happy!

    If you want to help me out once again, then try this one: http://www.devshed.com/Talk/Forums/F...ML/001134.html

    -Alex Suzuki
  28. #15
  29. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    9
    Rep Power
    0
    Lewi,

    I'm sorry that I called you out like that if you weren't trying to be rude.

    I agree the manuals hold the answers to most question and people often don't think enough for themselves.

    What I did not appreciate was the "never ask again" comment since it made it seem as if the initial question was inappropriate. (I realize I could have taken this the wrong way, though.)

    I think that this forum is great. It is great because people feel free to ask questions and others can learn from their mistakes. It is also great because people like Lewi have the answers to those questions and others can learn from their wisdom.

    I would hate it if people felt that they couldn't ask a question freely anymore because the answer is somewhere in the manual.

    I would also hate it if people like Lewi stopped answering questions because I can learn a lot from them.

    I am sorry that I offended people. Please accept my apology.

    Dogg
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 06:42 PM
  2. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  3. float question
    By yeah-yeah in forum HTML Programming
    Replies: 10
    Last Post: January 15th, 2004, 04:59 PM
  4. Inserting text into a database
    By icecubes7 in forum PHP Development
    Replies: 3
    Last Post: January 15th, 2004, 03:05 PM
  5. Writing Japanese unicode text to a mysql database
    By jayhay in forum PHP Development
    Replies: 3
    Last Post: January 13th, 2004, 09:10 AM

IMN logo majestic logo threadwatch logo seochat tools logo