Problem with String in html Form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ityd
Forum Newbie
Posts: 17
Joined: Tue Aug 08, 2006 8:16 am

Problem with String in html Form

Post by ityd »

Given a simple form:

Code: Select all

<form method="post" action="getMessage.php">
        <input type="text" name="message">
        <input type="submit" value="Submit">
    </form>
and the getMessage.php:

Code: Select all

<?php 
$message=$_POST['message'];
echo $message;
?>
Sampe Input: It's David's "Dog"

Sample Output: It\'s David\'s \"Dog\"

Why are the the quote being represented this way?
Is everyone's server like this? Or is this just the way my server is configured?

Thanks.

Sorry it seems I might have posted this is the wrong topic. Sorry in advance.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Is magic quotes on? If so, there are numerous ways to combat it, search this forum or the PHP website.
ityd
Forum Newbie
Posts: 17
Joined: Tue Aug 08, 2006 8:16 am

Post by ityd »

Thanks for the reply. Is there any special characters I could use to represent the quotes, so as to bypass magic quotes all together?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Handle the quotes properly and you'll be fine. Don't band-aid it.

get_magic_quotes_gpc() and/or get_magic_quotes_runtime() can be used in combination with stripslashes(). It's not that difficult.
ityd
Forum Newbie
Posts: 17
Joined: Tue Aug 08, 2006 8:16 am

Post by ityd »

lol ok thanks for you help
Post Reply