This is my 3rd post here about the same issue as was unable to draw attention of an advanced level programmer and earn proper knowledge about it.
A form that has the following code displays the success message every time on page launch in the browser logically but the form should display the success message only after it is submitted successfully.
This is the php syntax:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
[B][COLOR="RoyalBlue"]$message [/COLOR][/B]= "Record has been updated successfully.";
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE table SET name=%s, email=%s,
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
mysql_select_db($database_test, $test);
$Result1 = mysql_query($updateSQL, $test) or die(mysql_error());
$updateGoTo = "test.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
This is the html form part:
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center" class="test_table">
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="table-title">Name:</td>
<td class="table-content"><input type="text" name="name" value="<?php echo htmlentities($row_user['name'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="table-title">E-mail:</td>
<td class="table-content"><input type="text" name="email" value="<?php echo htmlentities($row_user['email'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="id" value="<?php echo $row_user['id']; ?>" />
<input class="submit" name="UpdateRecord" type="submit" id="UpdateRecord" value="Update Record" />
</form>
This is how the success message is called within a div on the page:
<p> <?php
if (!empty([B][COLOR="RoyalBlue"]$message[/COLOR][/B])) {
echo "<div class=\"successmessage\">" . [B][COLOR="RoyalBlue"]$message [/COLOR][/B]. "</div>";
}
?></p>
I can't point out the mistake that is causing improper output of success message.
Thanks in advance.