Page 1 of 1

php single record

Posted: Thu Apr 12, 2012 5:46 pm
by Shychild
Hi,

I would like to have a feature of what so called "single record".... like http://mywebsite.com/?id=1

pls help me!!

here's my code

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>TCB | Online Streaming | </title>
        <style type="text/css">
 #div{     background-color: #669999;
                        width: 450px;

        font-family:"Arial", Times, serif;
        text-align:justify;
        a:link {text-decoration:none;}    /* unvisited link */
a:visited {text-decoration:none;} /* visited link */
a:hover {text-decoration:underline;}   /* mouse over link */
a:active {text-decoration:underline;}  /* selected link */}
#news{
a:link {text-decoration:none;}    /* unvisited link */
a:visited {text-decoration:none;} /* visited link */
a:hover {text-decoration:underline;}   /* mouse over link */
a:active {text-decoration:underline;}  /* selected link */
  width: 450px;
  height: 450px;
    background-color: #99ffff;
  position: absolute; top: 500px; left: 0px;
}
</style>
        </head>
<body>
<div id="news"><div>
<img border="0" src="headline.jpg" alt="Programs" width="451" height="82">
        <?
$username="";
$password="";
$database="";

mysql_connect("",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news  ORDER BY id DESC LIMIT 3";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

?>

<?
$i=0;
while ($i < $num) {
$bck = ($i % 2 == 0 ) ? " style=\"background:#A3FFA3\"" : " style=\"background: #B7B7E8;\"";
$id=mysql_result($result,$i,"id");
$title=mysql_result($result,$i,"title");
$content=mysql_result($result,$i,"content");
$poster=mysql_result($result,$i,"poster");
?>

<div id="div" <? echo $bck ?>>
       <? echo $id;?>
        <? echo '<a href="http://www.mywebsite.com/index.php?id=' . $id . '">' . $title . '</a> <br/>'; ?>
<? echo $content; ?> <br> by <? echo $poster;?></div>
<?
$i++;
}

                ?></div></div>
</body>
        </html>

Re: php single record

Posted: Sat Apr 14, 2012 10:11 pm
by Shychild
Bump! Bump! pls help~

Re: php single record

Posted: Sat Apr 14, 2012 11:47 pm
by twinedev

Code: Select all

$query="SELECT * FROM news WHERE `id`=".(int)$_GET['id'];
Note the use of (int) to force $_GET['id'] to be a numeric value to prevent SQL injection.

Always use that for integer values, and everything else, use mysql_real_escape_string() to protect your queries.