Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2007, 09:21 AM   PM User | #1
oskare100
New Coder

 
Join Date: Dec 2006
Posts: 57
Thanks: 2
Thanked 0 Times in 0 Posts
oskare100 is an unknown quantity at this point
How to insert things into a MySQL database with an ' in?

Hello,
When I run this code:
PHP Code:
$sql55="INSERT INTO users (username, password, ebay_username, ebay_status, ebay_email, paypal_status, paypal_email, num_purchases, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_status, created) VALUES('".$row->account_username."', '".$row->account_password."', '".$row->auction_buyer_id."', '$ebay_status', '".$row->account_email."', '".$row->payer_status."', '".$row->account_email."', 1, '".$row->first_name."', '".$row->last_name."', '".$row->address_street."', '".$row->address_city."', '".$row->address_state."', '".$row->address_zip."', '".$row->address_country."', '".$row->address_status."', '$new_script_received')"
$result55 mysql_query($sql55) or die( mysql_error() ); 
I get the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S ROAD',"

Now it seams like the problem is this field "51 ST SIMONS'S ROAD" and I think the problem is the ', correct me if I'm wrong. How can I solve this problem? (It is a lot of rows I'm running this querey on so I can't just insert it manually).

Thanks in advance,
Best Regards
Oskar R
oskare100 is offline   Reply With Quote
Old 01-24-2007, 10:05 AM   PM User | #2
Alex!
Regular Coder

 
Join Date: Oct 2006
Location: Bristol
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Alex! is an unknown quantity at this point
use addslashes($row->address_street) to make it 51 ST SIMONS\'S ROAD and then when you call it from the database use stripslashes($row->address_street) to get it back to 51 ST SIMONS'S ROAD. For more information visit http://uk2.php.net/manual/en/function.addslashes.php

Alex
Alex! is offline   Reply With Quote
Old 01-24-2007, 01:01 PM   PM User | #3
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
use mysql_real_escape_string, see http://php.net/mysql-real-escape-string
__________________
My thoughts on some things: http://codemeetsmusic.com
And my scrapbook of cool things: http://gjones.tumblr.com
GJay is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:19 PM.


Advertisement
Log in to turn off these ads.