LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-03-2008, 03:04 PM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,079

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
php/mysql data INSERT problem


how do i get a php script to INSERT text data that contains characters such as ' or " without breaking the SQL query?
 
Old 09-03-2008, 03:31 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
addslashes($somevar);

so....

PHP Code:
$query "INSERT INTO user (user_id,
                             user_group,
                             user_displayname)
                     VALUES('$uid',
                            '$gid',
                            '"
.addslashes($displayname)."')";
mysql_query($query) or die('Query "' $query '" failed: ' mysql_error()); 
Of course, there are many different ways to do it, but that works.

Python has a slightly cleaner way of doing this, but... that's another story, I suppose.

Last edited by BrianK; 09-03-2008 at 03:32 PM.
 
Old 09-03-2008, 03:42 PM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,079

Original Poster
Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
thanks.. that worked ^^
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Inserting Data In A Mysql Database Using PHP Dapernia Programming 5 09-17-2007 10:05 AM
segmentation fault when insert data into mysql torontosmallbird Other *NIX 1 08-07-2005 07:13 AM
Problem inserting data into a mysql table using PHP Rockgod2099 Programming 13 08-03-2005 12:27 AM
Insert Data by FORM in MYSQL gruger Linux - Software 0 07-16-2003 12:50 PM
Problem Inserting MySQL data from PHP! rhuser Linux - Software 9 03-03-2003 07:56 PM


All times are GMT -5. The time now is 08:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration