PDA

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.

mr e
08-13-2002, 06:58 PM
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?

mr e
08-13-2002, 07:07 PM
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);
?>

Ajay
08-18-2002, 09:02 PM
use stripslashes()
i.e

$bad = 'good';
$string = 'Cupcakes are $bad"';
echo $string;

$string = addslashes($string);
eval("\$string = \"$string\";");
$string = stripslashes($string);

echo $string;