Need help with PHP text box...

Discussion in 'PHP' started by m_maheshwariin, Feb 2, 2009.

  1. #1
    Hello Friends,

    I m getting a problem with my php program...

    <?php

    if(isset($_POST['submit']))
    {
    $text = htmlspecialchars($_POST['text']);
    print $text;
    }

    print "
    <form method=post name=myform action=temp.php>
    <input type=text name=text>
    <input type=submit name=submit value=submit>
    </form>
    ";
    ?>

    this is very simple program... when i put ' or " to text box it returns \' and \"...

    although same program is working well with my local configuration. I m checking the things on PHP 2.5.8...

    Please i need a urgent solution for that...when i put ' and " to text box, it should return same thing to me ... not escape string..

    Thanks
     
    m_maheshwariin, Feb 2, 2009 IP
  2. simonhayes_

    simonhayes_ Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    
    if(isset($_POST['submit']))
    {
    $text = strip_slashes( htmlspecialchars($_POST['text']) );
    print $text;
    }
    
    print "
    <form method=post name=myform action=temp.php>
    <input type=text name=text>
    <input type=submit name=submit value=submit>
    </form>
    ";
    ?>
    PHP:
    That should work fine for you. :)
     
    simonhayes_, Feb 2, 2009 IP
  3. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Its stripslashes(), no underscore! :)

     
    Agent_Smith, Feb 2, 2009 IP
  4. simonhayes_

    simonhayes_ Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    :eek:

    I have my own function with the underscore that basically escapes all content. The above was a typo :D
     
    simonhayes_, Feb 2, 2009 IP
  5. m_maheshwariin

    m_maheshwariin Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks friends this is working really fine for website...
     
    m_maheshwariin, Feb 2, 2009 IP
  6. InovvativeTech

    InovvativeTech Banned

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The other soultion is you can turn OFF php magic quotes using .htaccess file

    php_value magic_quotes_gpc off
     
    InovvativeTech, Feb 3, 2009 IP