Thread: Help with mysql

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    14
    I have a form (like this one im typing in now) that lets users submit info into the database. I want it to let them submit apostrophes and other characters that mysql converts, or php converts before putting them in the database. It makes it print out like /'. How can i make it just accept and apostrophe, and print it out normally when i call it from the database. If this is confusing say so, ill show you an example.
    Thanks

    Sam
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    I just made a form for a database earlier today and tested it with all kinds of data - semicolons, mysl statements, echo statements... no problems when I pulled that data back out and put it on the screem. It should be said that the data type was VARCHAR for all the example feilds.

    If I am missing something orgiving incorrect information, please clarify.

    - Mike
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    14
    try out my script at: http://www.rpgswap.com/sell.php

    user/pass : sam/petulla

    when you submit an auction with an apostrophe or quotes... it puts a in front of it. I dont know why! its killing me!

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

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    14
    the more i test it the more screwed up it is. If i use a " in the description or title field, then the inserted value stops right before the ". So if i isert hello "sam". then it only inserts hello into the database. And of course there is the apostrohpe problem. AHHHH. help!!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    14
    I think this is a php problem. When php passes the variable from the first form to the second page, it is adding the ', so its not mySQL. Any ideas? Please help
  10. #6
  11. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    when using any variables, that can be user defined, in a query, i typically just escape all non-letter/number/whitespace characters with<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$var = preg_replace("/[^ws]/", "", $var);[/code]
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    23
    Rep Power
    0
    PHP has a special function for this problem. htmlspecialchars() works in php3 and php4 by converting problematic signs such as &, " and ' to its ascii code equivalent. Thus & becomes &amp. But your users won't know the difference. For more info, see http://www.php.net/manual/function.htmlspecialchars.php



    ------------------
    Aristotle concluded that those who admit their stupidity are truly wise.
    -
    Gil Hildebrand Jr
    4atcost.com Senior Web Developer
  14. #8
  15. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    You probably have PHP configured with 'magic_quotes_gpc = On', but with 'magic_quotes_runtime = Off' in php.ini (usually at /usr/local/lib).

    'magic_quotes_gpc' means PHP automatically escapes single or double quotes received from a GET, POST, or a cookie, which is why your database receives these values with the backslash in front of them. This is necessary, or your database would make a mess of your posted data.

    Try turning on 'magic_quotes_runtime' (for runtime-generated data), or use the function stripslashes() on your database-generated text.

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 06:02 PM
  2. Upgrade from access to mysql
    By karib1 in forum ASP Programming
    Replies: 7
    Last Post: December 16th, 2003, 12:35 PM
  3. Upgrade from access to mysql
    By karib1 in forum MySQL Help
    Replies: 1
    Last Post: December 16th, 2003, 12:27 AM
  4. problem: asp files, from access to mysql
    By karib1 in forum MySQL Help
    Replies: 1
    Last Post: November 26th, 2003, 03:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo