Why is it saying "Notice: Undefined variable: cnt in C:\Wamp\www\librarie\cos.php on line 24". Here is the code:
<?php
session_start();
include("conectare.php");
include("page_top.php");
include("meniu.php");
if (isset($_GET['actiune']) && ($_GET['actiune'] == "adauga"))
{
if (!isset($_SESSION['cnt']) || !$_SESSION['cnt'])
$_SESSION['cnt'] = '0';
$cnt = $_SESSION['cnt']; $cnt++;
$_SESSION['cnt'] = $cnt;
$_SESSION['nr_buc'][] = 1;
$_SESSION['pret'][] = $_POST['pret'];
$_SESSION['titlu'][] = $_POST['titlu'];
$_SESSION['nume_autor'][] = $_POST['nume_autor'];
}
if (isset($_GET['actiune']) && ($_GET['actiune'] == "modifica"))
{
for ($i=0; $i < $cnt; $i++)
{
$_SESSION['nr_buc'][$i] = $_POST['noulNrBuc'][$i];
}
}
?>
<td valign="top">
<div align="center">
<h1><img src="pictures/cumparaturi.png"></h1>
<form action="cos.php?actiune=modifica" method="post">
<table border="1" cellspacing="0" cellpadding="4">
<tr bgcolor="#F9F1E7">
<td><b>Nr. buc </b></td>
<td><b>Carte</b></td>
<td><b>Pret</b></td>
<td><b>Total</b></td>
</tr>
<?php
$cnt = $_SESSION['cnt'];
if (!isset($cnt)) $cnt = '';
$totalGeneral = 0;
for ($i=0; $i < $cnt; $i++)
{
//afisez randul doar daca numarul de bucati este diferit de 0
if ($_SESSION['nr_buc'][$i] != 0)
{
print '<tr>
<td><input type="text" name="noulNrBuc['.$i.']" size="1" value="'.$_SESSION['nr_buc'][$i].'"></td>
<td><b>'.$_SESSION['titlu'][$i].' de '.$_SESSION['nume_autor'][$i].'</td>
<td align="right">'.($_SESSION['pret'][$i]*$_SESSION['nr_buc'][$i]).' lei</td>
</tr>';
$totalGeneral = $totalGeneral + $_SESSION['pret'][$i]*$_SESSION['nr_buc'][$i];
}
}
print '<tr>
<td align="right" colspan="3"><b>Total in cos</b></td>
<td align="right"><b>'.$totalGeneral.'</b> lei</td>
</tr>';
?>
</table>
<br>
<input type="submit" value="Modifica"><br><br>
Introduceti <b>0</b> pentru cartile ce doriti sa le scoateti din cos!
<hr size="1" />
<h1><img src="pictures/continuare.png"></h1>
<table>
<tr>
<td width="200" align="center"> <img src="pictures/cos.JPG"><a href="index.php">Continua cumparaturile</a></td>
<td width="200" align="center"><img src="pictures/casa.JPG"><a href="casa.php">Mergi la casa</a></td>
</tr>
</table>
</form>
</td>
<?php
include("page_bottom.php");
?>
I tried using this 2 methods, but nothing:
1) error_reporting(E_ALL & E_NOTICE);
2) $cnt = $_SESSION;
if (!isset($cnt)) $cnt = '';