Problem displaying a mysql database field

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

    Problem displaying a mysql database field

    Hi,

    I have a varchar field in a MySQL database that contains a line of text
    like so:

    "This is a line if text"

    The double quotes are included in the database field.

    I cannot seem to display it on my HTML page, it always shows as blank.
    I have tried using both the stripslashes() and the html_entity_dec ode()
    but it still shows as blank.

    An code example I am trying is as follows:
    <?php
    echo
    stripslashes(ht ml_entity_decod e($my_variable_ from_a_mysql_da tabase));
    ?>

    How can I display this please???

    Tks,
    Don

  • Juliette

    #2
    Re: Problem displaying a mysql database field

    donpro wrote:[color=blue]
    > Hi,
    >
    > I have a varchar field in a MySQL database that contains a line of text
    > like so:
    >
    > "This is a line if text"
    >
    > The double quotes are included in the database field.
    >
    > I cannot seem to display it on my HTML page, it always shows as blank.
    > I have tried using both the stripslashes() and the html_entity_dec ode()
    > but it still shows as blank.
    >
    > An code example I am trying is as follows:
    > <?php
    > echo
    > stripslashes(ht ml_entity_decod e($my_variable_ from_a_mysql_da tabase));
    > ?>
    >
    > How can I display this please???
    >
    > Tks,
    > Don
    >[/color]


    Hmm.. my first intuition is to ask: are you sure the quotes are in the
    database ? (i.e. they haven't been removed when inserting)
    Have you looked at the database through phpMyAdmin or any such tool ?

    Test what you *really* get back from the database query to make sure you
    actually get the string properly from the database by doing a:
    print_r($query_ result);

    If the quotes are there, try this for displaying:
    print htmlentities(st ripslashes($my_ variable_from_a _mysql_database ),
    ENT_QUOTES);

    Good luck,
    Juliette

    Comment

    • totalstranger

      #3
      Re: Problem displaying a mysql database field

      On or about 6/20/2006 8:54 PM, it came to pass that Juliette wrote:[color=blue]
      > donpro wrote:[color=green]
      >> Hi,
      >>
      >> I have a varchar field in a MySQL database that contains a line of text
      >> like so:
      >>
      >> "This is a line if text"
      >>
      >> The double quotes are included in the database field.
      >>
      >> I cannot seem to display it on my HTML page, it always shows as blank.
      >> I have tried using both the stripslashes() and the html_entity_dec ode()
      >> but it still shows as blank.
      >>
      >> An code example I am trying is as follows:
      >> <?php
      >> echo
      >> stripslashes(ht ml_entity_decod e($my_variable_ from_a_mysql_da tabase));
      >> ?>
      >>
      >> How can I display this please???
      >>
      >> Tks,
      >> Don
      >>[/color]
      >
      >
      > Hmm.. my first intuition is to ask: are you sure the quotes are in the
      > database ? (i.e. they haven't been removed when inserting)
      > Have you looked at the database through phpMyAdmin or any such tool ?
      >
      > Test what you *really* get back from the database query to make sure you
      > actually get the string properly from the database by doing a:
      > print_r($query_ result);
      >
      > If the quotes are there, try this for displaying:
      > print htmlentities(st ripslashes($my_ variable_from_a _mysql_database ),
      > ENT_QUOTES);
      >
      > Good luck,
      > Juliette[/color]
      Suggest checking if magic quotes is on before doing a stripslashes
      Here's how I handle comments on my site. It allows for the preservation
      of both quote characters(sing le and double) and honors newlines
      converting them to <br />

      When storing the data:
      if (get_magic_quot es_gpc())
      {
      $a = stripslashes ($_POST[Pre_Comments]);
      $a = htmlspecialchar s($a, ENT_QUOTES);
      }
      else
      $a = htmlspecialchar s($a, ENT_QUOTES);

      On the HTML text generation after getting info from the database
      nl2br($i[Pre_Comments])

      Comment

      Working...