...

View Full Version : "Undefined index:" in form.



Peuplarchie
05-19-2008, 11:04 AM
Good night to you all,

I have a kind of shoutbox, flat file based, which give me an error :
"Undefined index:"

I know what this mean, but I don't see my mistakes can somebody help me ?





<?php

if ($_POST['nameq'] != "" && $_POST['messageq'] != "")
{
$nom = $_POST["nameq"];
$nomcorr = substr($nom, 0, -9);
$messageq = $_POST["messageq"];



$File = date('Y')."/".date('m')."/".date('d')."/messages.html";
$Handle = fopen($File, 'w+');

$Data = "<b class=\"red\">$nom</b>";
$Data.= $messageq;
$Data.= "<br/></br/>";
fwrite($Handle, $Data);

fclose($Handle);


}

?>




<form action="" method="post">
<input type="text" name="nameq" value="<? echo $_SESSION['Name'];?>"/>
<?
echo "<select name=\"COLOUR_CHOICE\" id=\"COLOUR_CHOICE\">";

$colourArray = array("000000", "cccc99", "FFFFFF", "0000FF");
for ($i = 0; $i < count($colourArray); $i++)
{
$selected = ($colourArray[$i] == trim($_POST['COLOUR_CHOICE'])) ? 'selected="selected"' : '';
echo '<option value="' . $colourArray[$i] . '"' . $selected . ' . id="opt' . $colourArray[$i] . '">#' . $colourArray[$i] . '</option>';
}
echo "</select>";
?>

<textarea name="messageq"></textarea>
<input type="submit" name="Envoyer !!!" value="post"/>
</form>







Thanks!
Have a good one !

abduraooft
05-19-2008, 11:22 AM
It's due to the usage any uninitialised variables somewhere is the page. Check the line number along with the error!
Also see http://in2.php.net/error_reporting , if you really want to suppress this notice.

Peuplarchie
05-19-2008, 12:00 PM
Bingo, I had to use isset :


if (isset($_POST['nameq'])) {


Thanks !

aedrin
05-19-2008, 08:49 PM
if you really want to suppress this notice.

This is a really bad idea. You don't want to ever suppress warnings/errors.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum