www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] Drop Down Selection that has an apostrophe

  1. #1
    Join Date
    May 2009
    Posts
    233

    resolved [RESOLVED] Drop Down Selection that has an apostrophe

    I have created a select list but one of the names has an apostrophe. I when I echo then name it has a backslash in it. How do I fix this?

    Here is the partial page list.php
    And the result after the selection is: Assignments for Perpetua D\'Souza
    PHP Code:
    <form name="form" action="list.php" method="get">
    <table cellpadding="2">
    <tr><td><select name="q">
    <option value=""></option>
    <?php
    //sql1 - finding LSS
    include("../connectdb.php");
    $sql1 "SELECT * FROM directory WHERE department='Legal Support Services' ORDER BY name";
    $result1 mysql_query($sql1) or die("Couldnt execute query: ".mysql_error());
    while (
    $rows=mysql_fetch_array($result1)) {
    echo 
    "<option value=\"$rows[name]\">$rows[name]</option>";
    }
    ?>
    </select></td><td><input type="image" value="Submit" src="../images/select.jpg" border="0" />
    </td></tr>
    </table>
    </form>
    <?php
    $var 
    $_GET['q'];
    $name explode(','$var);

    if (
    $var == ""){
    echo 
    "<p>Please select the operator...</p>";
    exit;
    }
    ?>
    <p class="head">Assignments for <?php echo "$name[1] $name[0]"?></p>
    etc...

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    Is it in the database that way? If so, you probably need to disable magic_quotes_gpc in your PHP configuration (and run an update query on your DB to get rid of the slashes that ended up in there.)

    If you cannot modify the PHP config, then you should run stripslashes() on the inputs before processing them and adding them to your DB.

    If that is not feasible for some reason, then you can run stripslashes() on the output, but that's really just a band-aid and not a real fix.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2009
    Posts
    233
    How does one disable magic_quotes_gpc. Also there are no slashes in the database the slashes show up when I echo results. So D'Souza is in the database correctly but prints as D\'Souza.

  4. #4
    Join Date
    Oct 2007
    Posts
    370

    Disable magic_quotes_gpc


  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    Perhaps you have magic_quotes_runtime enabled?
    PHP Code:
    ini_set('magic_quotes_runtime'false); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    I hear PHP is going to ditch magic quotes soon. I'm glad, as it's been a thorn in my side more than once.

  7. #7
    Join Date
    May 2009
    Posts
    233
    Does the following code go into a php.ini file

    PHP Code:
    ini_set('magic_quotes_runtime'false); 

  8. #8
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    I believe that code would go in the file you wish to disable magic quotes on. Sort of an on the fly option.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles