Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

quotes and apostrophes



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old February 23 '05, 07:14 AM (#1)
jbagley is offline
WDF Senior Member
 
jbagley's Avatar
 
Join Date: September 2004
Location: Cape Town
Posts: 845
jbagley is on a distinguished road
Send a message via MSN to jbagley
quotes and apostrophes

What is the best way of handling them when it comes a Database driven application?

I know the methods used are stripslashes and addslashes, but what is best practice? Do you add the slashes before you insert into the database and then strip them before you print it out to the screen?

Is there a better or faster way of doing it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 23 '05, 08:14 AM (#2)
rosland is offline
Retired Staff
 
rosland's Avatar
 
Join Date: July 2003
Location: Norway
Posts: 1,939
rosland is a jewel in the roughrosland is a jewel in the roughrosland is a jewel in the roughrosland is a jewel in the rough
Quote:
Originally Posted by jbagley
Do you add the slashes before you insert into the database and then strip them before you print it out to the screen?
Yes.

Quote:
Originally Posted by jbagley
Is there a better or faster way of doing it?
None that I can think of.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 23 '05, 08:25 AM (#3)
jbagley is offline
WDF Senior Member
 
jbagley's Avatar
 
Join Date: September 2004
Location: Cape Town
Posts: 845
jbagley is on a distinguished road
Send a message via MSN to jbagley
Ok, cool. Thanks Rosland. I was just checking I was doing it the right way...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 24 '05, 04:39 PM (#4)
visualAd is offline
Restructuring
 
visualAd's Avatar
 
Join Date: January 2003
Location: Slough, UK
Posts: 201
visualAd will become famous soon enough
Quote:
Originally Posted by jbagley
What is the best way of handling them when it comes a Database driven application?

I know the methods used are stripslashes and addslashes, but what is best practice? Do you add the slashes before you insert into the database and then strip them before you print it out to the screen?

Is there a better or faster way of doing it?
Its a googd idea to check whether magic quotes is turned on, otherwise you run the risk of escaping your string twice. Something like this:
PHP Code:
function stripslashes_safe($string)
{
    
/* why the space in the $stirng variable I don't know, 
       but the forum software insists on putting it there */
    
return get_magic_quotes_gpc()?$string:stripslashes($string);

Its also worth noting that some database management systems have different methods for escaping quotes. MS for example uses a '' to escape a quote.

Last edited by visualAd; February 24 '05 at 04:41 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 8 '05, 05:39 AM (#5)
jbagley is offline
WDF Senior Member
 
jbagley's Avatar
 
Join Date: September 2004
Location: Cape Town
Posts: 845
jbagley is on a distinguished road
Send a message via MSN to jbagley
I need some help implementing a solution to escape apostrophes and quotations.

I am running MSSQL.
PHP Code:
$first addslashes(trim(@$_POST['firstname'])); 
This is the code I am using. If I use single quotes(') it prints this out: jason\'s, and it fails.

But if I use double quotes(") It works and prints this out: jason\"s. Here is the insert statement:
PHP Code:
$sql "INSERT INTO ClientContact 
        (CDLID, first, surname, cellno, email, field1, field2, field3) 
        VALUES 
        ("
.$_SESSION['CDLID'].",'".$first."','".$surname."','".$cellno."','".$email."','".$field1."','".$field2."','".$field3."')"
I need a solution for both single and double quotes to work Thanks in advance
P.S. Ive turned magic quotes off.

Last edited by jbagley; March 8 '05 at 05:40 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


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

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

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


 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:33 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163