Hjælp til få PHP til at gemme værdier i sessions
Jeg har levet en kode, hvor jeg forsøger at gemme en værdi i $_SESSION. Man skriver den ønskede værdi ind i et inputfelt og trykker gem. Derefter reloader siden og den skriver den intastede værdi i det samme inputfelt. Så langt så godt.Problemet opstår når jeg prøver at skifte side for derefter at komme tilbage til siden igen. Den husker simpelthen ikke værdien.
Her er koden (ved godt den er meget lang):
<?php
session_start();
?>
<html>
<head>
<link rel="Stylesheet" href="style.css" type="text/css">
</head>
<body>
<?
$albumnavn = $_GET['album'];
$prot = $_GET['prot'];
$pass = $HTTP_POST_VARS['kode'];
$database = mysql_connect("localhost","root","");
mysql_select_db("foto",$database);
$foresp = mysql_query("select navn, antal, prefix, first, format, mappe, kode from albums where navn='$albumnavn'");
while ($data = mysql_fetch_array($foresp)) {
$navn = stripslashes($data["navn"]);
$antal = stripslashes($data["antal"]);
$prefix = stripslashes($data["prefix"]);
$first = stripslashes($data["first"]);
$format = stripslashes($data["format"]);
$mappe = stripslashes($data["mappe"]);
$kode = $data["kode"];
}
echo $kode;
echo "<br>";
echo $pass;
if (($pass==$kode) || ($prot==$kode)) {
$side = $_GET['side'];
$plus = 1;
$nummer = 16*($side-1);
$row = 1;
$col = 1;
?>
<form name="gem" action="visning.php?album=<? echo $albumnavn ?>&side=<?php echo $side ?>&prot=<? echo $kode ?>" method="post">
<table width="800">
<?php
while (16*($side-1)<=$nummer&&$nummer<=16*$side-1&&$nummer<=$antal-1) {
if ($col==1) {
if ($row==1) {
if ($plus==1) {
if ($HTTP_POST_VARS[$first+$nummer] && $HTTP_POST_VARS[$first+$nummer]!="") {
$HTTP_SESSION_VARS[$first+$nummer] = $_POST[$first+$nummer];
} else {}
?>
<tr><td><table width="100%"><tr><td class="visning-left" width="50%">
<table width="100%"><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="<? echo $first+$nummer; ?>" size="2" maxlength="2" value="<? echo $HTTP_SESSION_VARS[$first+$nummer]; ?>"></p></td></tr></table>
<? $plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table width="100%"><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==2) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==3) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==4) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table></td>
<?
$plus = 1;
$nummer = $nummer+1;
$row = 1;
$col = 2;
}
} else {
}
}
}
}
} else {
if ($row==1) {
if ($plus==1) {
?>
<td width="100%"></td><td><table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==2) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
\" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==3) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlengtht"2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table>
<?
$plus = 1;
$nummer = $nummer+1;
$row = $row+1;
}
} else {
if ($row==4) {
if ($plus==1) {
?>
<table width="100%"><tr><td class="visning-left" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-left-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
<?
$plus = 2;
$nummer = $nummer+1;
} else {
?>
</td><td class="visning-right" width="50%">
<table><tr><td>
<img src="albums/
<? echo $mappe; ?>
/
<? echo $prefix;
echo $first+$nummer;
echo $format; ?>
" height="100px"></td></tr><tr><td class="visning-right-input">
<p>Antal:
<input type="text" name="
<? echo $first+$nummer; ?>
" size="2" maxlength="2"></p></td></tr></table>
</td></tr></table></td></tr>
<?
$plus = 1;
$nummer = $nummer+1;
$row = 1;
$col = 1;
}
} else {}
}
}
}
}
}
if ($plus==1) {
echo "</td></tr></table>";
} else {
}
if ($col==1) {
echo "</tr>";
} else {
if ($row==4) {
} else {
echo "</td></tr></table></td></tr>";
}
}
echo $side;
?>
</table>
<input type="text" name="ass" value="<? echo $HTTP_POST_VARS['ass']; ?>">
<input type="reset" value="Slet alt">
<input type="submit" value="Gem">
</form>
<p>FUCKING PIS! 10 <br>
<? echo $HTTP_SESSION_VARS[1169]; ?>
</p>
<? echo $HTTP_POST_VARS['ass']; ?>
<?
if ($side!=1) {
?><a href="visning.php?album=<? echo $albumnavn; ?>&side=<? echo $side-1 ?>&prot=<? echo $kode ?>">Forrige side</a><?
} else {}
if ($side*16<$antal) {
?><a href="visning.php?album=<? echo $albumnavn; ?>&side=<? echo $side+1 ?>&prot=<? echo $kode ?>">Næste side</a><?
} else {}
} else {
?>
<p>Koden var forkert! Gå tilbage og prøv igen.</p>
<?
}
?>
</body>
</html>