FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to write a wroth script for write and read from database





phicha
I know ussually we write a data to mysql table using

Code:
mysql_query("insert into table values('".$a."','".$b."','".$c."')",$db);


but for security reason we add like this
Code:
$a = mysql_real_escape_string($HTTP_POST["a"]);
$b = mysql_real_escape_string($HTTP_POST["b"]);
$c = mysql_real_escape_string($HTTP_POST["c"]);


and when we want we read from a table like this
Quote:
$query=mysql_query("select * from table",$db);
while($row=mysql_fetch_row($query))
{
$a=stripslashes ($row[0]);
$b=stripslashes ($row[0]);
$c=stripslashes ($row[0]);
}


that only i know, am my script is safe and worth enough ? thanks.
and i have others question either,
1. how about that i want make a user also can input a lines in a textbox
2. how about i want restirect my user input a html tag ?

what function or combinated function should i used ?

thanks.
phicha
Er i want to give a example like, if a user create a username like this

B<b>ol</b>d , if we dont add a some function of course the output will be Bold

i want to know if what function should we used for encode & decode when we save & read data from a databases.
hexkid
phicha wrote:
1. how about that i want make a user also can input a lines in a textbox
2. how about i want restirect my user input a html tag ?


1. nl2br()
2. htmlentities(), or strip_tags()
phicha
Thanks for the info,
but i wonder which good to used it first ?
i meant which way is the good way

Quote:
$htm=nl2br(htmlentities($a));


or

Quote:
$htm=htmlentities(nl2br($a));


?
hexkid
phicha wrote:
i wonder which good to used it first ?
i meant which way is the good way

Quote:
$htm=nl2br(htmlentities($a));


or

Quote:
$htm=htmlentities(nl2br($a));


?


Try them both and you'll learn the correct way right away.
Related topics
script backup database
PHP script trouble
Looking for a Javascript shoutbox
multiple mysql connections
Can someone please help me with my website?
How to search in a MySQL - database
Can I write a script for the following application?
Problem with AGP read and write settings
What is RSS Feed?
My phpBB 2.0.22 mods are giving problems
i need this,pls help
string comparison
Locking database with write access
php msql quiz script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.