Apostrophe woes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vic Spainhower

    #1

    Apostrophe woes

    Hello,

    I have in my drop-down menu company names that can have apostrophe's
    imbedded i.e. Vic's Coffee Shop which shows fine in the menu. However, when
    the user updates other fields on the form and presses the update buton it is
    truncating the company name field and it only sees the data in front of the
    ' sign i.e. Vic. You'll notice that right after the foreach($_POST as
    $field => $value) I am echoing the results of each field and the company
    field is truncated after the ' sign. Magic Quotes is on if this has anything
    to do with the problem.

    Can someone please tell me why???

    TIA

    Vic


    Here's the code to load the dropdown menu:
    <?PHP
    $table = "tblCompani es";
    $Link = mysql_connect ($host, $user, $password);
    $Query = "select concat(compID,' ; ',compName)
    as comp_name from $table";
    $results = mysql_db_query( $database, $Query, $Link);
    ?>
    <tr><td align="right">< b>Delivery Company:</b></td>
    <td><select name = "theCompany " >
    <Option Value=" ">Select Delivery Company:</option>
    <?PHP
    for($u=0;$u<mys ql_num_rows($re sults); $u++)
    {
    $company=mysql_ result($results ,$u,'comp_name' );
    echo "<option value='$company '";
    if ($company == $searchCompany)
    {
    echo "selected";
    }
    echo ">$company\ n";
    ?>
    </option>
    <?PHP
    }
    ?>
    </select>

    when the form is updated and the page is reloaded thiscode is run :

    case "Update":
    foreach($_POST as $field => $value)
    {
    echo "value of $$field is $value ;";

    if ($field == "theCompany ")
    {
    $$field = strip_tags(trim ($value));
    $pos = strpos($$field, ";");
    $len = strlen($$field) ;
    $searchCompany = $$field;
    $compID = substr($$field, 0, $pos); // returns the company id
    }


  • Markku Uttula

    #2
    Re: Apostrophe woes

    Vic Spainhower wrote:[color=blue]
    > I have in my drop-down menu company names that can have apostrophe's
    > imbedded i.e. Vic's Coffee Shop which shows fine in the menu.
    > However, when the user updates other fields on the form and presses
    > the update buton it is truncating the company name field and it only
    > sees the data in front of the ' sign i.e. Vic.[/color]

    Well now...

    echo "<option value='$company '>"

    Produces the following in your code:

    <option value='Vic's Coffee Shop'>

    I believe you see the problem? Try this instead:

    echo '<option value="'.htmlsp ecialchars($com pany).'"';
    if ($company == $searchCompany)
    {
    echo "selected";
    }
    echo ">$company\ n";

    --
    Markku Uttula

    Comment

    • Vic Spainhower

      #3
      Re: Apostrophe woes

      Markku,

      This certainly works and now I had better go read about the htmlspecialchar s
      function.

      I am very new to php and I really do appreciate your help in this. I'm
      certain I'd never have found this on my own.

      Vic


      "Markku Uttula" <markku.uttula@ disconova.com> wrote in message
      news:M6rXd.76$U I3.62@reader1.n ews.jippii.net. ..[color=blue]
      > Vic Spainhower wrote:[color=green]
      >> I have in my drop-down menu company names that can have apostrophe's
      >> imbedded i.e. Vic's Coffee Shop which shows fine in the menu. However,
      >> when the user updates other fields on the form and presses
      >> the update buton it is truncating the company name field and it only
      >> sees the data in front of the ' sign i.e. Vic.[/color]
      >
      > Well now...
      >
      > echo "<option value='$company '>"
      >
      > Produces the following in your code:
      >
      > <option value='Vic's Coffee Shop'>
      >
      > I believe you see the problem? Try this instead:
      >
      > echo '<option value="'.htmlsp ecialchars($com pany).'"';
      > if ($company == $searchCompany)
      > {
      > echo "selected";
      > }
      > echo ">$company\ n";
      >
      > --
      > Markku Uttula[/color]


      Comment

      Working...