Variable Sesiune
Scris: Sâm Dec 05, 2009 6:51 pm
Doresc sa fac o rezervare a unei camere dintr-un hotel.Codurile camerelor disponibile sunt stocate in $_SESSION['rooms']
Afisarea o fac
<?php foreach ($_SESSION['rooms'] as $room): ?>
<tr>
<td><?php htmlout($room['rcod']); ?></td>
<td><?php htmlout($room['rnume']); ?></td>
<td> <form action="setupcart.php" method="post">
<input type="hidden" name="rcod" value="<?php htmlout($room['rcod']); >"/>
<?php echo '<input type="submit" name="action" value="'.$room['mod'].'"/>' ?>
</form>
</td>
</tr>
<?php endforeach;?>
Afisarea este corecta, dar nu reusesc sa pastrez continutul lui $_SESSION['rooms'].Nu ar trebui sa ramana valabil in setupcart.php?
if (!isset($_SESSION['rooms'])) echo 'nu mai este $_SESSION[rooms]';
if (!isset($_SESSION['cart']) ) $_SESSION['cart'] = array();
//Apasare buton REZERVA pentru una din camere
if (isset($_POST['action']) and $_POST['action'] == 'Rezerva')
{
$_SESSION['cart'][] = $_POST['rcod'];
foreach($_SESSION['rooms'] as $k => $rooms)
{
if (strcmp($rooms['rcod'],$_POST['rcod'])==0) $_SESSION['rooms'][$k]['mod']='Anuleaza';
}
}
Obtin :
nu mai este $_SESSION[rooms]
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\stildespotiko\setupcart.php on line 9
Multumesc,
Mirela
Afisarea o fac
<?php foreach ($_SESSION['rooms'] as $room): ?>
<tr>
<td><?php htmlout($room['rcod']); ?></td>
<td><?php htmlout($room['rnume']); ?></td>
<td> <form action="setupcart.php" method="post">
<input type="hidden" name="rcod" value="<?php htmlout($room['rcod']); >"/>
<?php echo '<input type="submit" name="action" value="'.$room['mod'].'"/>' ?>
</form>
</td>
</tr>
<?php endforeach;?>
Afisarea este corecta, dar nu reusesc sa pastrez continutul lui $_SESSION['rooms'].Nu ar trebui sa ramana valabil in setupcart.php?
if (!isset($_SESSION['rooms'])) echo 'nu mai este $_SESSION[rooms]';
if (!isset($_SESSION['cart']) ) $_SESSION['cart'] = array();
//Apasare buton REZERVA pentru una din camere
if (isset($_POST['action']) and $_POST['action'] == 'Rezerva')
{
$_SESSION['cart'][] = $_POST['rcod'];
foreach($_SESSION['rooms'] as $k => $rooms)
{
if (strcmp($rooms['rcod'],$_POST['rcod'])==0) $_SESSION['rooms'][$k]['mod']='Anuleaza';
}
}
Obtin :
nu mai este $_SESSION[rooms]
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\stildespotiko\setupcart.php on line 9
Multumesc,
Mirela