POST and $
I am trying to make all $_GET methods into $_POST on this page. I want php?produktid=0 to be invisible on the adress bar. How can I solve this?
This is an application and I want it to run on its own.
//PREVIOUS BUTTON
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo '<a href="newarrivals.php?produktid=' . ($index - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </a> ';
} else {
echo '<a href="newarrivals.php?produktid=' . (count($array) - 1) . '"> <img style="margin-left: 77px;" src="prev.png"> </a> ';
}
echo "</td>";
//IF I AM ON PAGE ONE, ECHO THIS
if($_GET['produktid']==0){
echo "<p>Page One</p>";
}
//IF I AM ON PAGE TWO, ECHO THIS
if($_GET['produktid']==2){
echo "<p>Page Two</p>";
}
//IF I AM ON PAGE THREE, ECHO THIS
if($_GET['produktid']==3){
echo "<p>Page Three</p>";
}
//NEXT BUTTON
echo "<td>";
if ($index < count($array) - 1) {
echo '<a href="newarrivals.php?produktid=' . ($index + 1) . '"> <img style="margin-left: -70px;" src="bilder/next.png"> </a> ';
} else {
echo '<a href="newarrivals.php?produktid=0"> <img style="margin-left: -70px;" src="next.png"> </a>';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
HERE IS HOW MY WHOLE PAGE LOOKS LIKE
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#Latest_products {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="latest_products">
<?php
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify Photo Sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//PREV BUTTON
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo '<a href="newarrivals.php?produktid=' . ($index - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </a> ';
} else {
echo '<a href="newarrivals.php?produktid=' . (count($array) - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </a> ';
}
echo "</td>";
//FOR PAGE 1 SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//FOR PAGE 2 SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//FOR PAGE 3 SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<td>";
//NEXT BUTTON
if ($index < count($array) - 1) {
echo '<a href="newarrivals.php?produktid=' . ($index + 1) . '"> <img style="margin-left: -70px;" src="bilder/next.png"> </a> ';
} else {
echo '<a href="newarrivals.php?produktid=0"> <img style="margin-left: -70px;" src="bilder/next.png"> </a>';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
After I change it looks like this now, and "PREV" "NEXT" links doesn't work now.
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#senaste_produkter {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="senaste_produkter">
<?php
//Databasuppkoppling - Visa senaste produkter ifrån databasen
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify picture sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//BACK LINK
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input style="margin-left: 77px;" src="bilder/prev.png"></form>';
} else {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="'. (count($array) - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </form>';
}
echo "</td>";
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 2, SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<td>";
//NEXT PAGE
if ($index < count($array) - 1) {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="' . ($index + 1) . '"> <img style="margin-left: -70px;" src="bilder/next.png"> </a> ';
} else {
echo '<form action="newarrivals.php"> <img style="margin-left: -70px;" src="bilder/next.png"> </a>';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
You need to use forms instead of links, and put the parameters into hidden inputs. So change
echo '<a href="newarrivals.php?produktid=' . ($index - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </a> ';
to:
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input type="image" style="margin-left: 77px;" src="bilder/prev.png"></form>';
and change all the other links similarly.
Here's the whole rewritten script:
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#senaste_produkter {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="senaste_produkter">
<?php
//Databasuppkoppling - Visa senaste produkter ifrån databasen
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify picture sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//BACK LINK
$index = $_GET['produktid'];
echo "<tr><td>";
if ($index > 0) {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input type="image" style="margin-left: 77px;" src="bilder/prev.png"></form>';
} else {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="'. (count($array) - 1) . '"> <input type="image" style="margin-left: 77px;" src="bilder/prev.png"> </form>';
}
echo "</td></tr>";
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 2, SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<tr><td>";
//NEXT PAGE
if ($index < count($array) - 1) {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index + 1) . '"> <input type="image" style="margin-left: -70px;" src="bilder/next.png">';
} else {
echo '<form action="newarrivals.php" method="post"> <input type="image" style="margin-left: -70px;" src="bilder/next.png">';
}
echo "</td></tr>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
链接地址: http://www.djcxy.com/p/60706.html
下一篇: POST和$