Problem inserting into database

02-03-07, 02:00 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Problem inserting into database
Hey Guys,
Trying to make a script where i just fill a textarea in and sends the text into a database, but the problem i have is when there is any ' in the text i got 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 're firmly established at the very heart of British life, providing the freshest ' at line 1
but if i dont use ' it goes in fine? Can anyone help?? my text is below
Can someone have a look at my code and see what i need to do?
Thank you in advanced
__________________
Power is in my programming fingers
Last edited by Nico; 02-03-07 at 02:04 PM.
Reason: Fixed [/php] wrapper.
|

02-03-07, 09:11 PM
|
|
Coding Addict
|
|
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do you have an apostrophe or single quote of some sort in your text? If you do then you need to use addslashes otherwise sql complains.
My guess is that you have something like "they're" right there and the string is trying to close at the apostrophe rather than at the end of the string where you expect it to.
__________________
"Things are difficult only while you don't understand them."
|

02-04-07, 06:20 AM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yea thats the problem i am having, But because its a textarea and want users to enter ' and any other special characters, what do i do?
__________________
Power is in my programming fingers
|

02-04-07, 07:05 AM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

02-04-07, 07:14 AM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
__________________
Power is in my programming fingers
|

02-04-07, 07:27 AM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
Half. Use mysql_real_escape_string() on all user defined variables you're going to insert.
And you can do it directly like this.
And if $id2 is supposed to be a numeric value, I'd use intval() on it.
www.php.net/intval
|

02-04-07, 11:12 AM
|
 |
Coding Addict
|
|
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
also, i find it that
sometimes in my code, the output changes but sometimes this wont word:
and you need to do this:
but like i said my output usually varies
|

02-04-07, 02:14 PM
|
 |
Newbie Coder
|
|
Join Date: Aug 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
could you export your mysql table for us?
Last edited by HoTDaWg; 02-04-07 at 02:14 PM.
Reason: incorrect english
|

02-05-07, 02:11 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok for some reason this is not inserting into a database
The error i get is this
PHP Warning: mysql_real_escape_string(): A link to the server could not be established in /home/f/o/foodplanet/public_html/info/extratext2.php on line 7
__________________
Power is in my programming fingers
|

02-05-07, 02:11 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
if you need it this is the page with the form in
__________________
Power is in my programming fingers
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|