RE: odbc query with single quote in string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I'm having problem querying a table with a field value containing an
> appostropy, please help.  Using ODBC to connect MSAcess database.
> 
>    $mQuery = "CustomerID='$mCust'";
>    $mCur2 = odbc_do( $mCnx, "select Login from Emails where $mQuery"
);
> 
> When it hits "O'Donald, James", I get error in odbc_exec().  I tried
> variations of $mQuery, including:
> 
>    $mQuery = addslashes( $mQuery );

You don't want to use addslashes() on $mQuery, you want to use it on the
data you're inserting between the quotes, i.e. $mCust. 

$mQuery = "CustomerID='" . addslashes($mCust) . "'";

If that still causes an error, your database may require quotes to be
escaped with another quote, instead of a backslash. In that case, you
can create a function like this

function addslashes2($data)
{ return str_replace("'","''",$data); }

Hope that helps.	

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux