POST和$
我正在尝试在此页面上将所有$ _GET方法变为$ _POST。 我希望php?produktid = 0在地址栏上不可见 。 我该如何解决这个问题?
这是一个应用程序,我希望它自己运行。
//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>";
?>
这里是我的整个页面如何看起来像
<!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>
我改变它现在看起来像这样,“PREV”“NEXT”链接现在不起作用。
<!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>
您需要使用表单而不是链接,并将参数放入隐藏的输入中。 所以改变
echo '<a href="newarrivals.php?produktid=' . ($index - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </a> ';
至:
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>';
并相似地更改所有其他链接。
这是整个重写的脚本:
<!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/60705.html
上一篇: POST and $
下一篇: Lua & Lighttpd