jayant325
(Jayant Eng)
April 29, 2014, 6:53am
1
I have an apostrophe in username and while adding that in DB first I am checking whether that username exist in DB or not but its giving error. Below is the code snippet.
$username = $_POST[‘username’];
$usr_exist = YumUser::model()->findByAttributes(array(‘username’ => $username));
How to bypass apostrophe while checking in DB. The username is like: TES’T
hothummus
(Redishen)
April 29, 2014, 8:32am
2
Have you tried addslashes()?
jayant325
(Jayant Eng)
April 29, 2014, 8:43am
3
Yes I tried with addslashes(). Didn’t work.
mr.right
(Mr Right748)
April 29, 2014, 10:30am
4
I don’t think there’s a problem in you code. What specific error did you encountered?
jayant325
(Jayant Eng)
April 29, 2014, 11:04am
5
NetworkError: 500 CDbException
Keith
(Kburton)
April 29, 2014, 12:45pm
6
Firstly, you don’t need addslashes. Yii will parameterize the query, making the input safe for you. Using addslashes will cause the value not to match.
Secondly, network error suggests that there’s an issue with your database config or your network. What’s the full error message?
jayant325
(Jayant Eng)
April 30, 2014, 9:42am
7
Keith:
Firstly, you don’t need addslashes. Yii will parameterize the query, making the input safe for you. Using addslashes will cause the value not to match.
Secondly, network error suggests that there’s an issue with your database config or your network. What’s the full error message?
Its 500 PHP Error. There should not be any issue with network configuration because only an apostrophe is causing the issue.
When I am executing the same script with str_replace its working fine. For Example,
$username = $_POST[‘username’];
$username = str_replace("’","",$username);
$usr_exist = YumUser::model()->findByAttributes(array(‘username’ => $username));
It works with no error.
jkofsky
(Jkofsky)
April 30, 2014, 6:14pm
8
Maybe:
$usr_exist = YumUser::model()->findByAttributes(array('username' => PDO::quote($username)));