How to Secure IDs For a MySQL Query
Posted: Mon May 16, 2011 7:39 pm
hi.
how are you there this is my first tutorail in this website.
les get start;
we know the id is primerkey we use in database table to count or to make in order
imagen that you want to make a blog
and the url is will be like this
the file will be like this
that we make normal
how are you there this is my first tutorail in this website.
les get start;
we know the id is primerkey we use in database table to count or to make in order
imagen that you want to make a blog
and the url is will be like this
localhost/blog/index.php?topicid=number like 1 in examplefor example
localhost/blog/index.php?topicid=3So it will bring data form the row 3 in database table
the file will be like this
that we make normal
<?php /** * @Author: Muhanned Mohammed * @contry: Oman * @email: kaka9909@hotmail.com * */ // contact to databse mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); //make query $page=$_GET['topicid']; // ?topicid= $query=mysql_query("SELECT * FROM table_name WHERE id='$page'") or die("error"); } ?>but for securty we wil user array
<?php /** * @Author: Muhanned Mohammed * @contry: Oman * @email: kaka9909@hotmail.com * */ // contact to databse mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); //make query // sec we will use array $page=$_GET['topicid']; // topicid= if(is_int($page)){ $array=array("-","+"); $page=str_replace($array,"",$page); // this will delete the - ,+ in the url : localhost/blog/index.php?topicid=2 } $query=mysql_query("SELECT * FROM table_name WHERE id='$page'") or die("error"); ?>