php with single and double quotation marks

Discussion in 'Software' started by man_im_bored, Mar 10, 2005.

  1. man_im_bored

    man_im_bored Private E-2

    Hey all

    One thing that I've been meaning to look at for a while, and now am forced to look at, is apostrophies and them in php.

    For example:

    If someone enters into a text field "My Dad's brand new car". The value of that text field goes to a database..which the code would obviously look something like this

    PHP:
    $subject $_POST["subject"];
    $query "INSERT INTO myDBtable (subject) VALUES ('$subject')";
    But of course, thats gonna cause a problem because what mysql is seeing is

    INSERT INTO myDBtable (subject) VALUES ('My Dad's brand new car')

    the apostrophie in "Dad's" is causing it to think thats its finished.

    I've seen people using slashes (/) but it hasn't been explained properly.
    Even if someone has a reference to another website, would be helpful.
     
  2. Philipp

    Philipp Administrator Staff Member

    You are looking for addslashes()

    PHP:
    $subject addslashes($_POST["subject"]);
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds