Current location: Hot Scripts Forums » Programming Languages » PHP » single quote "'" error in mysql query by php


single quote "'" error in mysql query by php

Reply
  #1 (permalink)  
Old 09-27-05, 01:05 AM
sjems sjems is offline
Newbie Coder
 
Join Date: Apr 2005
Location: USA
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
single quote "'" error in mysql query by php

I have got error while displaying the data having single quote "'". for example "I am some one. I don't know anything." while showing the data either only shows "I am some one. I don" or nothing shown except error. Please help me to solve the problem. i am using Php 4 or later and latest mysql verson at myisam tables
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-27-05, 01:16 AM
arstanj's Avatar
arstanj arstanj is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sjems
I have got error while displaying the data having single quote "'". for example "I am some one. I don't know anything." while showing the data either only shows "I am some one. I don" or nothing shown except error. Please help me to solve the problem. i am using Php 4 or later and latest mysql verson at myisam tables

PHP Code:

<?php

// Connect
$link mysql_connect('mysql_host''mysql_user''mysql_password')
   OR die(
mysql_error());

// Query
$query sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
           
mysql_real_escape_string($user),
           
mysql_real_escape_string($password));
?>
Happy coding!
__________________
Happy coding!

----------------------------
http://www.jusupov.com - Computer Technology Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-27-05, 03:25 AM
sjems sjems is offline
Newbie Coder
 
Join Date: Apr 2005
Location: USA
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by arstanj
PHP Code:

<?php

// Connect
$link mysql_connect('mysql_host''mysql_user''mysql_password')
   OR die(
mysql_error());

// Query
$query sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
           
mysql_real_escape_string($user),
           
mysql_real_escape_string($password));
?>
Happy coding!
is this code work in insert query too?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-27-05, 03:55 AM
arstanj's Avatar
arstanj arstanj is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
It should work but.... the best way to learn is to TRY.

Happy coding!
__________________
Happy coding!

----------------------------
http://www.jusupov.com - Computer Technology Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-27-05, 09:36 AM
mkovach159 mkovach159 is offline
New Member
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
you have disabled magic quotes. You can:
  1. change in php.ini from magic_quotes_runtime = Off
    to magic_quotes_runtime = On
  2. write this line of code at the beggining of your php script :
    PHP Code:
    
    set_magic_quotes_runtime(1); 
    
  3. the best solution - use mysql_escape_string function before insterting of value to the database.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM
Complex mysql sorting pb (Get cat_list from cids &pcids with 1 query, willing to pay) aqw PHP 1 06-23-05 08:02 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 01:55 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.