hmm, what do i do with /// and ""?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

hmm, what do i do with /// and ""?

Post by qads »

:?
this is a sql statment, but i guess you know that :P

Code: Select all

$sql = "INSERT INTO q_comments (section, title,name,email,comment,script_id,date) VALUES ('$sec', '$com_title', '$user10', '$email1', "$comments", '$s_id', '$date')";
first, it did't let me enter ' in to $comments, so i add \" \" round it, then it did't let enter "
so i used $comments = addslashes($comments); to add \ to "

so now if some one uses " in $comments i get alot of \\\.

how can i fix this so it can take " and ' without any \


lol, i just find it funny for some reason :? :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you do your insert:

Code: Select all

$comments = addslashes($comments);
$sql = "INSERT INTO q_comments (section, title,name,email,comment,script_id,date) VALUES ('$sec', '$com_title', '$user10', '$email1', '$comments', '$s_id', '$date')";
and to get the information ready to display:

Code: Select all

$comments = htmlspecialchars(stripslashes($comments));
You have to have the slashes to put the information into the database so you use stripslashes() to get rid of them at the other end. htmlspecialchars() is also useful for changing things like &, < and > into html entities so that they can be displayed.

Mac
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

thanks, it came to me after i turned my computer off :evil:

so i am useing just stripslashes();.
Post Reply