Good day to you all,
I have a piece of code for a little shootbox on single page.
So you have a form, when a message is submit, the code write it to a file; messages.html.
My problem with this part is that the way I use, take the whole content of the html page add to it, at the bottom, the result of the submit PLUS another copy of that result, so it’s duplicating all the time ???
I have tried different fopen modes.
Second : I need to have some code at the begining of the html file, how can I not overwrite it when I copy the meesage into the html file ?
[code=php]
<?php
if (isset($_POST[‘nameq’])) {
if ($_POST[‘nameq’] != “” && $_POST[‘messageq’] != “”)
{
$nom = $_POST[“nameq”];
$nomcorrecting = strtoupper($nom);
$nomcorr = substr($nomcorrecting, 0, -9);
$messageq = $_POST[“messageq”];
$choice = $_POST[“COLOUR_CHOICE”];
$nomcoul = “<font color=”#”.$choice.”” size=”3″>”.$nomcorr.”</font> <br/>”.$messageq.”<br/><br/>”;
$File = date(‘Y’).”/”.date(‘m’).”/”.date(‘d’).”/messages.html”;
$Handle = fopen($File, ‘r+’);
if ($Handle) {
$buffer = fgets($Handle, 4096);
$Data = $nomcoul .’nr’. $buffer;
fwrite($Handle, $Data);
fclose($Handle);
}
}
}
?>
<center>
<h3>Nouveau message…</h3>
<iframe id=”myframe” name=”myframe” src=”<? echo date(‘Y’).’/’.date(‘m’).’/’.date(‘d’).’/messages.html’; ?>” scrolling=”auto” marginwidth=”0″ marginheight=”0″ frameborder=”0″ style=” width:580px; height:400px;”></iframe>
<form action=”” method=”post”>
<input type=”hidden” name=”nameq” value=”<? echo $_SESSION[‘Name’];?>”/>
<textarea name=”messageq” cols=”70″ rows=”5″></textarea><br/>
<b>Couleur du text : </b>
<?
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>”;
?>
<input type=”submit” name=”Envoyer !!!” value=”post”/>
</form>
Thanks !
Ha a nice day !