recently started to trawl through an existing intranet so that it will work on the latest versions of PHP and MYSQL.
I am aware that i have to change the way variable's are handled i.e
$bob = $_POST["bob"] instead of $bob = $bob
Problem lies in using the new method where the $_POST variable has not been defined yet. One example is isset($submit) where the form posta to itself $PHP_SELF.
I get "Notice: Undefined index: submited in " - How can i change my code to correct this problem? Please see below example:
Code: Select all
<?php
if ($submited == "yes"){
ConnectNoticeBoard();
$ip = $_SERVER['REMOTE_ADDR'];
$time = date(Ymd);
$url = "No thanks";
$sql = "INSERT INTO shoutbox
VALUES(NULL,'$names','$shouts','$url','$time','$ip')";
mysql_query($sql)or die(mysql_error().'<p>'.$sql.'</p>');
// mysql_close();
// print("window.location.reload()");
}
?>
<div align="left"></div>
<form name="shoutForm" id="shoutForm" method="post" action="<? $PHP_SELF ?>" >
<div align="center" valign="top">
<input type="text" id="names" name="names" size="22" maxlength="30" class="shoutform" value="name" onFocus="ClearField(this)">
<input type="text" id="shouts" name="shouts" size="22" value="shout" maxlength="500" class="shoutform" onFocus="ClearField(this)">
<br>
<br>
<input type="button" name="shout" value="shout" class="shoutbutton" onClick="verifyShoutbox(this.form)"><input name="submited" type="hidden" id="submited">
</div>
</form>
<?php
ConnectNoticeBoard();
$sql = "select t.shout, t.name from shoutbox t order by id desc LIMIT 15";
$result = mysql_query($sql);
mysql_close();
print("<table width="90%" border="0" cellspacing="2" cellpadding="2" valign="top" align="center">");
while ($record = mysql_fetch_array($result,MYSQL_ASSOC)) {
$output[$count]=array( 'nick' => stripslashes($record["name"]),
'shout' => stripslashes($record["shout"]));
$count++;
}
// $output = array_reverse($output);
//---------------------------------------
foreach ($output as $shout) {
$row = mysql_fetch_array($result);
$Shout = $row["shout"];
$name = $row["name"];
print("<tr valign="top" align="left">");
print("<td width="90%">");
printf("<span class="shouttext"><b>%s</b>%s%s</span>",$shout["nick"],": ",$shout["shout"]);
print("</td>");
print("</tr>");
}
print("</table>");
$submited ="no"
?>