TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-16-2011, 05:58 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Magic Quotes

A real beginner question but i'm having difficulty with escaping input form data containing commas. Eg. Name entered as O'Neill. I'm checking magic quotes is switched off in th php.ini file which it is so i'm not stripping slashes from the input data. I am however using the mysql real_escape_string function on the data before adding it to the database. Its stored on the database as O'Neill and not O/'Neill however when i retrieve it using mysql SELECT statement the pho code is displaying it as O. Do i need to add a backslash to php knows its not the end of a string but actually part of the string?

Any general advice on this?

Cheers.
captainmerton is offline  
Reply With Quote
Old 01-16-2011, 06:13 PM   #2 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

The problem i appear to be having is when i try and display the name as values in a form:

PHP Code:
    <tr>
    <td>
        <label for="name">Property Name*</label>
    </td>
    <td>
        <input type='text' name='name' id='name' size='50' maxlength='50' value='<?php print $property->getName(); ?>'>
    </td>
    </tr>
    <tr>
    <td>
        <label for="details">Property Details*</label>
    </td>
    <td>
        <textarea name='details' id='details' cols='75' rows='10'><?php print $property->getDetails(); ?></textarea>
    </td>
    </tr>
If both $property->getName() and $property->getDetails() return O'Neill the name form text appears as O whereas its appears as O'Neill in the details textarea input field. I'm sure its something to do with the the different form input types and the text input type is treating the comma as the end of the string. Any idea how i can resolve this?
captainmerton is offline  
Reply With Quote
Old 01-16-2011, 06:19 PM   #3 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

I've fixed it by changing the ' to a ". I know the way php treats these is quite different. I assume it was treating it as a variable as opposed to a string. Not sure.
captainmerton is offline  
Reply With Quote
Old 01-16-2011, 07:27 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

if you still want to use ' to delimit strings you can scape internal ' by escaping them with t backward slash \'

"" display the contents of variables if they are inside of strings like

PHP Code:
<?php
$s 
"string";
echo 
"this is a $s"//echoes to this is a string
echo 'this is a $s'//echoes to this is a $s
?>
tony is offline  
Reply With Quote
Old 01-18-2011, 06:55 PM   #5 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

If you aren't escaping the ' then the HTML becomes this:

HTML Code:
<input type='text' name='name' id='name' size='50' maxlength='50' value='O'Neil'>
You can see the value is then messed up so the browser thinks "O" is the value and ignores the rest.

The fix would be to use addslashes in your form so that it escapes quotes.

PHP Code:
<input type='text' name='name' id='name' size='50' maxlength='50' value='<?php print addslashes($property->getName()); ?>'>
Then the HTML would be

HTML Code:
<input type='text' name='name' id='name' size='50' maxlength='50' value='O\'Neil'>
Which is correct.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
single quotes or double quotes in php planepixel Absolute Beginners 5 02-04-2009 05:48 AM
sttripslashes, addslashes, magic quotes, queries... Killswitch General 0 12-10-2008 03:57 AM
How do you structure your quotes? Aaron The Lounge 10 01-01-2008 04:49 AM
My Favourite PHP Magic Method: __call Wildhoney Advanced PHP Programming 10 11-16-2007 03:32 AM
Differences Between Single and Double Quotes Wildhoney General 19 11-10-2007 11:37 PM


All times are GMT. The time now is 04:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design