PDA

View Full Version : [php] notice: undefined index


ndakota
19-08-2007, 23:36
ho appena inziato con il php e noto che anche se copio codice dal libro che sto usando mi da molto di questi errori. sapete a cosa è dovuto?

Traxsung
20-08-2007, 07:06
puoi postare il codice che esegui ?

ndakota
20-08-2007, 10:38
checkbox.html

<html>
<head><title></title></head>
<body>
<form method="POST" action="checkbox.php">
have you ever eaten haggis before?
<input name="Choice1" type="checkbox" value="Haggis">
<br>
have you ever eaten snails before?
<input name="Choice2" type="checkbox" value="Snails">
<br>
have you ever eaten locusts before?
<input name="Choice3" type="checkbox" value="Locusts">
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

checkbox.php

<html>
<head><title></title></head>
<body>
<?php
echo "$_POST[Choice1]<br>";
echo "$_POST[Choice2]<br>";
echo "$_POST[Choice3]<br>";
?>
</body>
</html>

se do le spunte me li stampa e tutto a posto se non le do mi da quei notice.. ma comunque non solo in questo, anche in altri copiati pari pari dal libro, mi sembra strano.

Xalexalex
20-08-2007, 11:02
checkbox.html

<html>
<head><title></title></head>
<body>
<form method="POST" action="checkbox.php">
have you ever eaten haggis before?
<input name="Choice1" type="checkbox" value="Haggis">
<br>
have you ever eaten snails before?
<input name="Choice2" type="checkbox" value="Snails">
<br>
have you ever eaten locusts before?
<input name="Choice3" type="checkbox" value="Locusts">
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

checkbox.php

<html>
<head><title></title></head>
<body>
<?php
echo "$_POST[Choice1]<br>";
echo "$_POST[Choice2]<br>";
echo "$_POST[Choice3]<br>";
?>
</body>
</html>

se do le spunte me li stampa e tutto a posto se non le do mi da quei notice.. ma comunque non solo in questo, anche in altri copiati pari pari dal libro, mi sembra strano.

Ti dà un notice di "undefined index"perchè i campi dell'array non sono pieni dal momento che non hai spuntato le caselle. Ti ricordo che in php le variabili non le dichiari, ma queste esistono solo nel momento in cui hanno contenuto. (L'ho detta un po' grezza, qualcuno magari usi dei termini più tecnici :D )
Non è nulla di che, semplicemente nel php.ini il livello di error_reporting è un po' troppo alto... Per evitare questo problema edita il php.ini e aggiungi alla riga di error_reporting "~ E_NOTICE"...
Yaoz :D