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

    Join Date
    Mar 2014
    Posts
    47
    Rep Power
    3

    $variable with apostrophe problem


    Hi Folks,
    I am banging my head on this .
    My script creates 2 files "first.php" and "second.php" and the content of the first file is "John" and the second file "Da'silva"
    I am using these files throughout the script.
    A folder of these 2 names joined together is also automatically created the folder name is "JohnDa'silva".
    PHP Code:
    ob_start();                     
    include(
    'first.php');  
    $contenta ob_get_contents();    
    ob_end_clean();                  

     
    ob_start();                     
    include(
    'second.php');   
    $contentb ob_get_contents();    
    ob_end_clean(); 
    The script works perfect with all names without special characters.
    The problem is when I use the following:
    PHP Code:
    $result "SELECT * FROM table where firstname='$contenta' AND lastname='$contentb' limit 1 ";
           foreach (
    $conn->query($result) as $row)
            {
    echo 
    ucfirst($row['firstname']) . ' ' ucfirst($row['lastname']);

    The script is having the single ' and double " conflicts. I have tried the backslach \' but the conflicts is still not ruled out. I also tried changing to " " but the conflicts ares till there. I need to have the last name available as is at all times. I do not want to remove the apostrophe in a name.
    I would appreciate it very much if someone can perhaps point out to me what I am doing wrong or the solution to this conflict?

    PS: these 2 names goes in the database as is.

    Thank you very much in advance
    Last edited by netfreak; November 16th, 2015 at 05:08 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,196
    Rep Power
    601
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    47
    Rep Power
    3
    WoW! what do you know? Man, it worked like a charm... Thanks very much for the quick response and the solution. I tried almost everything except your solution. I feel like a dummy for not seeing/knowing that. Maybe I was too much inside that I FAIL to see the depth.

    For those who may wonder what the solution is:
    PHP Code:
    $lastnamecfg addslashes($contentb);
     AND 
    lastname'$lastnamecfg' 
    Once again, Thanks
    Have a nice day...
    Greetings
    Last edited by netfreak; November 16th, 2015 at 06:02 PM.

IMN logo majestic logo threadwatch logo seochat tools logo