I have create a small site where data can be filtered depending on where the user has clicked the checkbox.I read in a book that when the GET method is used is allows the user to bookmark the page because it gives out a unique url with the processed data, this is a something i want to use in my application.
My problem is when i use the GET method, choose which rows i would like to be filtered and then click submit. The page flickers like it has been processed but the data has not be filtered, but when i change everything to POST, the data is filtered but the URL is not unique stopping me from bookmarking the page.
This is the coding for the page.
<html>
<head>
<title></title>
</head>
<body>
<?php
if (!isset($_POST['submit'])){
?>
<?php
$host = 'localhost';
$user = 'root';
$pass = 'mysql';
$db = 'Jokes';
$conn = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect");
mysql_select_db($db) or die ("ERROR:Unable to run dB");
$select = "SELECT * FROM joke"; //displays all the data within the table
$sresult = mysql_query($select) or die ("ERROR:Unable to run query");
echo "<form action=$_SERVER[PHP_SELF] method=POST>";
echo "<table border=1 cellpadding=3 cellspacing=3><tr>";
echo "<td><p align=center>ID</td></center>";
echo "<td><p align=center>Joke</td></center>";
echo "<td><p align=center>Date</td></center>";
echo "<td><p align=center>Show?</td></center>";
echo "</tr>";
echo "<tr>";
while ($row=mysql_fetch_array($sresult)){
echo "<td>".$row['id']. "</td>";
echo "<td>".$row['JokeText']. "</td>";
echo "<td>".$row['JokeDate']."</td><br />";
echo "<td><p align=center><input type=checkbox name=$row[id] value=showhide></center></td>";
echo "</tr>";
}
echo "</table>";
echo "<br />";
echo "<input type=submit name=submit value=Submit>";
echo "</form>";
} else {
$host = 'localhost';
$user = 'root';
$pass = 'mysql';
$db = 'Jokes';
$conn = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect");
mysql_select_db($db) or die ("ERROR:Unable to run $db");
// coding below is to prevent SQL Injection (well i think so)
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
echo "<table border=1 cellpadding=3 cellpadding=3>";
echo "<tr>";
echo "<td><p align=center>ID</td></center>";
echo "<td><p align=center>Joke</td></center>";
echo "<td><p align=center>Date</td></center>";
echo "</tr>";
foreach ($_POST as $id => $id){ //when the ID number has been submitted from the select query will run.
if ($id == 'submit'){
exit();
}
$select = sprintf("SELECT * FROM joke where id= %s", //select the data which has the same ID number sa the one submitted.
quote_smart($id));
$sresult = mysql_query($select) or die ("ERROR:Unable to run query");
while ($row=mysql_fetch_array($sresult)){
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['JokeText']."</td>";
echo "<td>".$row['JokeDate']."</td>";
}
echo "</tr>";
}
echo "</table>";
}
/*
while ($row=mysql_fetch_array($sresult)){
if (!$row['id'] == ' '){
$select = "SELECT * FROM joke where id = $row[id]";
$sresult = mysql_query($select) or die ("ERROR:Unable to run query".mysql_error());
*/
?>
</body>
</html>
Help ?!?
Thanks