0
*<form action="" method="post">
  <br><br><br>
  <label style="padding-left:40px; font-size:28px; height:24px;">To</label>
  <input type="text" name="mail" style="width:280px; height:24px;"></input>
  <br><br>
  <textarea rows="10" cols="41" name="notify" style="margin-left:50px;"> 
  </textarea>
  <br><br>
  <input type="reset" value="Reset" style="margin-left:80px; width:100px; height:30px;"></input>
  <input type="submit" value="Send" name="send" style="margin-left:50px; width:100px; height:30px;"></input>
 </form>* 

this is a part of my html code

 *<?php
  if(isset($_POST['mail'])&&isset($_POST['notify']))
   {
    $email=$_POST['mail'];
    $notification=$_POST['notify'];
    if(!empty($email)&&!empty($notification))
     {
      include "db.php";
      $query="insert into notification(email,notification) values('$email','$notification')";
      $result = mysql_query($query);
      if($result)
       {
        $_SESSION['mail']=$email;
        $_SESSION['notify']=$notification;
       }
     }
   }
 ?>*

this is a part of my php code. I have started the session already The code is running fine I can enter email and notification in database. But I want the notification to get displayed in another page. I can display the notification. But each time I submit notification to the same email the new notification replaces the old notification. I want to show every notification each time user submits in a new page.

I have coded for new page as follows

    *<?php
     session_start();
     if($_SESSION['login_user']==$_SESSION['mail'])
      {
        echo '<div id="notificationdiv" style="background-color:#CFC; width:100%; height:30px">'.$_SESSION['notify'].'</div>';   
      } 

?>*
Birju
  • 95
  • 9
  • 1
    As you appear to be a beginner, please learn `PDO` or `MYSQLI_` database extension and not the `MYSQL_` extension you are using here. The `mysql_ `extension is dead and will not be in the next release of PHP (7) [Have a read of this](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) to help decide which you prefer to learn – RiggsFolly Aug 17 '15 at 17:28
  • what do you mean by "it replaces the old notification" ? are you using ajax? you need to give us more detail – CodeGodie Aug 17 '15 at 17:30
  • Not all universities are teaching pdo and mysqli. It could be for a homework assignment. Also, not all fortune 100 companies use the latest version of php. – crh225 Aug 17 '15 at 17:31
  • 1
    Just because they dont teach it or use it, doesnt mean that they should not. They all shoud be working on the latest. It is definitely recommended to use mysqli over mysql as it will one day be completely gone. – CodeGodie Aug 17 '15 at 17:36
  • @crh225 somehow I doubt fortune 100 companies even use php...probably they use java – developerwjk Aug 17 '15 at 17:39

1 Answers1

1

Hopefully I am understanding you correctly. But from the looks of it you will need to append / add the new notification to the old one by concatenation:

For example (example 1):

$_SESSION['notify'] .= $notification . ',';

Currently you are over writing your previous notification. In the above example I have split the notifications with a comma. you can use and other special character to separate them for example.

For example (example 2)

$_SESSION['notify'] .= $notification . '/';

You can then use explode to separate the notifications

For Example (for example 1):

$notifications = explode( ',' , $_SESSION['notify']);

foreach($notifications as $notification){

 echo  '<div>' . $notification . '</div>';    

}

For Example (for example 2):

$notifications = explode( '/' , $_SESSION['notify']);

foreach($notifications as $notification){

 echo  '<div>' . $notification . '</div>';    

}
Jono M
  • 91
  • 2
  • 9