Hello everyone!

I’m new to the board, but I’m hoping that someone can help me with this issue. I have an application written mostly in PHP, but uses HTML forms to collect data from users. The data is stored in a MySQL database. Anywho, the problem occurs if a user enters data such as 15" monitor or 50' cord into the form. In the database the data is displayed correctly. But in the browser it is truncated to either 15 (if single quotes used in input tag) or 50 (if double quotes used in input tag). What can I do so that no matter which type of measurement a user inputs, it will be displayed correctly? The user's input is held in $description. Below is the input code I used

<input type = 'text' size = '40' name = 'pdescription' value ='<?php echo $description; ?>'></input>

Thanks a bunch! 🙂

    use mysql_real_escape_string($value) when inserting data into database.

    use echo htmlentities($description, ENT_QUOTES); to display the information.

      troybtj wrote:

      use mysql_real_escape_string($value) when inserting data into database.

      use echo htmlentities($description, ENT_QUOTES); to display the information.

      What if the data is already in the database with the single or double quote in the measurement? How can I get it to display properly?

        Hi, over there.

        Use km (kilometer), m (meter), dm (decimeter), cm (centimeter) and mm (millimeter)
        and problems will be less ( = international standard units, used by scientists, too )

        Regards 😉

          halojoy wrote:

          Hi, over there.

          Use km (kilometer), m (meter), dm (decimeter), cm (centimeter) and mm (millimeter)
          and problems will be less ( = international standard units, used by scientists, too )

          Regards 😉

          I wish that were an option, but unfortunately the products don't come in those standards.

            melanie74 wrote:

            What if the data is already in the database with the single or double quote in the measurement? How can I get it to display properly?

            If the data is already in the database correctly, simply use the

            <?php echo htmlentities($description, ENT_QUOTES); ?>

            to display the information. That encodes the ' and " into HTML escaped/encoded format for proper display.

            From: http://www.php.net/manual/en/function.htmlentities.php

            <?php
            $str = "A 'quote' is <b>bold</b>";
            // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
            echo htmlentities($str, ENT_QUOTES);
            ?>
            

            --Edit: You'll need to visit the link above to see the actual output, since the forum software is converting the quotes from the code...

              troybtj wrote:

              If the data is already in the database correctly, simply use the

              <?php echo htmlentities($description, ENT_QUOTES); ?>

              to display the information. That encodes the ' and " into HTML escaped/encoded format for proper display.

              From: http://www.php.net/manual/en/function.htmlentities.php

              <?php
              $str = "A 'quote' is <b>bold</b>";
              // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
              echo htmlentities($str, ENT_QUOTES);
              ?>
              

              --Edit: You'll need to visit the link above to see the actual output, since the forum software is converting the quotes from the code...

              I'll have to take a look at this again because I tried this and did not get anything different.

                Write a Reply...