View Full Version : Um.. Apostrophes and PHP..
Coolj
08-13-2002, 06:26 PM
Um.. Apostrophes and PHP..
I use ashnews (http://projects.ashwebstudios.com)
and recently in my new host when I submit something with an apostrophe it gives me a mysql connect error, but when I put a \ in front it goes through.. ex
He's a good fella.
Will not go through..
He \ ' s a good fella.
Will go through.
i dont know what the question was, but if you do an apostrophe or a quote you have to escape it with a \ before it
Coolj
08-13-2002, 06:59 PM
If there any way around this? Like by using str_replace?
oh ok, well to automatically escape EVERYTHING you surround the string with '' (single quotes) but if you do
<?
$test = blue;
print 'the sky is $test';
?>
that wont work because $test is automatically escaped, but if you dont have any variables in it then single quotes would work
Coolj
08-13-2002, 07:12 PM
Hmm..
Coolj
08-13-2002, 07:29 PM
Everytime I submitted something with an apostrophe, i'd get a mysql cannot connect error. A friend of mine told me how to fix it..
<?php
$textarea = addslashes($textarea);
?>
use stripslashes()
i.e
$bad = 'good';
$string = 'Cupcakes are $bad"';
echo $string;
$string = addslashes($string);
eval("\$string = \"$string\";");
$string = stripslashes($string);
echo $string;
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.