Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
Storing info with apostrophes in database and selecting with sql
Welcome,
Guest
. Please
login
or
register
.
December 02, 2008, 05:40:12 AM
11304
Posts in
1248
Topics by
498
Members
Latest Member:
katCheeme
Home
Help
Search
Login
Register
Experts Round Table Network
|
Databases
|
MySQL
|
Storing info with apostrophes in database and selecting with sql
« previous
next »
Pages:
[
1
]
Print
Author
Topic: Storing info with apostrophes in database and selecting with sql (Read 1153 times)
jamin84
Offline
Posts: 4
Storing info with apostrophes in database and selecting with sql
«
on:
September 26, 2007, 08:22:26 AM »
I set up a database to store information for a certificate course (title, description, objectives, date, location) and am retrieving the information to display on a web page. The description contains apostrophes and every forum I've looked at addresses the problem of inserting and selecting, but I just need to know how to store the information in order to select it without getting question marks in their places.
Logged
rdivilbiss
Governing Council Member
Offline
Posts: 414
Re: Storing info with apostrophes in database and selecting with sql
«
Reply #1 on:
September 26, 2007, 11:46:51 AM »
If you use MySQL prepared statements to insert and select information from the database, apostrophes will not be a problem or issue.
See: PHP MySql Prepared Statements Library in the ArticleWiki under PHP.
Otherwise you'll need to escape apostrophes before inserting the data into the database and unescape them before displaying the data on a web page.
Logged
Rod
jamin84
Offline
Posts: 4
Re: Storing info with apostrophes in database and selecting with sql
«
Reply #2 on:
September 26, 2007, 12:39:24 PM »
I looked at the PHP MySql Prepared Statements Library but couldn't put any of it to use.
I am using phpmyadmin to insert the data into the fields. I'm not sure how to use prepared statements to insert the data, can I edit the data directly somehow? How would I escape the apostrophes with phpmyadmin?
Logged
VGR
Mentor
Offline
Posts: 682
Re: Storing info with apostrophes in database and selecting with sql
«
Reply #3 on:
September 26, 2007, 01:12:25 PM »
humm you're not very clear. Anyway if your problem lies in quotes (single quotes, because double quotes are theoretically not a problem in SQL), just do an addslashes() call before posting to the DB, and do a stripslashes() after reading. it's as simple as that. good practice anyway to do this on all string (eg, char, *text or varchar) columns.
Logged
techie overlord, answers all kind of questions on
http://www.europeanexperts.org
jamin84
Offline
Posts: 4
Re: Storing info with apostrophes in database and selecting with sql
«
Reply #4 on:
September 26, 2007, 02:08:35 PM »
Thanks for replying, I hope to make it clearer!
I am not using any SQL directly to insert the data. I open the table and cut and paste the information all in phpmyadmin, so I don't know where I would invoke the addslashes function. I tried simply adding backslashes to the data (right before the single quote), fetching my query with php/sql and calling the stripslashes function when I captured the data which didn't work.
Furthermore, if I manually replace all the single quotes in phpmyadmin directly, it seems to fix the problem.
Logged
VGR
Mentor
Offline
Posts: 682
Re: Storing info with apostrophes in database and selecting with sql
«
Reply #5 on:
September 27, 2007, 12:00:43 PM »
eactly. phpmyadmin si crap. I only use the console. phpmyadmin is crap. you can't specify the charset, skip-quotes etrc when performing a mysqldump(). Use standard tools. phpmyadmin is crappy. it doesn't even do an addslash(). phpmyadmin is sh**t
BTW, I have a script called "vgrdb.php" that you may find on my site, wgich I made before phpmyadmin even existed ; it automatically adapts to your server's data (databases, table layouts etc) and offers add/edit/delete functions.
I have an other one which is a freeform QBE (so it's a QB without the "E" ;) whose strnegth is the ability to work with oracle, mysal and/or sql-server all at the same time. pgsql was under work when I stopped.
Logged
techie overlord, answers all kind of questions on
http://www.europeanexperts.org
Pages:
[
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com