I trying to separate the code php and the code html in 2 files.
So I’m doing many functions that will be executed in different part of my page.
For the moment I’m trying to make a function for saving a small form data.
So I have written that code:
function addAnnonce($session) {
$sql = "SELECT `nom`,`prenom`,`type` FROM `gestionnaire` WHERE `id`={$session}";
$result = mysql_query($sql);
$donnees = mysql_fetch_assoc($result);
}
function saveAnnonce($form, $annonce, $to) {
if (isset($form)) {
addAnonce($_SESSION['login']);
$by = $donnees['nom'] . ' ' . $donnees['prenom'];
$sql = "INSERT INTO `cometchat_announcements` SET
`announcement` ='" . mysql_real_escape_string($annonce) . "',
`by` ='" . mysql_real_escape_string($by) . "',
`time` ='" . mysql_real_escape_string(time()) . "',
`to` ='" . mysql_real_escape_string($to) . "'";
mysql_query($sql);
echo "<div class=\"success\">L'annoncea bien été ajoutée , vous pouvez continuer vos actions<br>La mise à jour interviendra après actualisation</div>";
echo "<SCRIPT type=\"text/javascript\">
<!--
alert(\"Ajout d\'une nouvelle annonce : Ok !\");
// -->
</SCRIPT> ";
}
}
isset($_POST['enreg']) ? saveAnnonce($_POST['enreg'], $_POST['annonce'],$_POST['to']) :'' ;
The trouble is that it display to me a blank page.
I really do not understand why.
It should display the form but I think something is wrong but I can not see what.
I’ve tried it with xdebug but it does not show to me nothing.
Any kind of help will be much appreciated.
You are not returning
$donneesto the workflow, so$donneesinsaveAnnonce()is not defined.