Forum Moderators: coopster
if(isset($_GET['username'])){
$authorUsername = $_GET['username']; //DISPLAYS AS: we'
$authorComment = $_GET['comment'];$myProfilePic2 = "<img src='/users/".$authorUsername."/".$authorUsername.".ProfilePic.".$dbConn->getUserPicExtension($authorUsername)."' />";
In the above code, the extra apostrophe (') in we' throws off the whole syntax in $myProfilePic2. The code works on names without apostrophes, but for users whose name contains apostrophes, it all goes downhill.
How do I work around/fix this if I want to retain the original user's name (we') without having to strip off the apostrophe? Thanks
$authorUsername = [url=http://www.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]($_GET['username']);
Try that and see how it works out for ya. :)
<img src="/users/".$authorUsername."jpg" />
So say the name is we', then the ideal image path would be something like <img scr="/users/we'.jpg. But you see, the apostrophe screws everything up when the script is trying to figure out the path.
Maybe there's something obvious I am missing?
I am currently using mysql_real_escape_string(stripslashes($data)) to prep for DB insertion. If I have a string like we', then we' gets inserted into the DB. Is this wrong?
I tried inserting we\' in DB also, but it was giving me nightmares in getting the correct output, so I reverted to the above.
I though about replacing the apostrophe with nothing, but that would mess up the names: we' -> we. As you can tell, I am a bit confused about this, so please clarify how I should approach this issue.
/users/we'.jpg exists on the server? If so then I don't see why you would be having any troubles. If not, then that is your answer. As far as putting characters such as the apostrophe (') in usernames in the first place...well that is something I would tend to avoid. I usually only allow alphanumeric characters and the underscore in my usernames; anything else would be invalid and prompt them to choose a new one. This decision is up to you, but I would seriously consider going that route.
[edited by: eelixduppy at 3:55 am (utc) on Aug. 19, 2009]
In any case, I'm sure you got it all figured out by now. Glad to help. :)