Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    75
    Thanks
    1
    Thanked 2 Times in 2 Posts

    My announcement system

    Hi, I'm trying to make a smooth announcement bar.

    This is what I have. The first code is included in every page of my website so that users who didn't read the announcements, they can view it on any page until they have read or closed out of the announcement box.

    PHP Code:
    <?
    $announcement 
    mysql_connect("localhost","username","password");
    if (!
    $announcement)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("database"$announcement);

    $result mysql_query("SELECT * FROM announcement WHERE username='username'");

    if(
    $_SERVER['REQUEST_METHOD'] == "POST")  {

    mysql_query("UPDATE `announcement` SET `read` = 'yes' WHERE `username` = 'username'");
                }
    else {

    while(
    $row mysql_fetch_array($result))
    if (
    $row[read] == 'yes')
    {
    echo 
    ""// I echo nothing because if they already read the announcements, they don't need to read anything else.
    } else {
    include(
    'announcement.php');
    }
    }
    ?>
    And the second part is calling out the announcement from the database.

    PHP Code:
    <?
     $server 
    'localhost';
     
    $user 'username';
     
    $pass 'password';
     
    $db 'database';
     
     
    // Connect to Database
     
    $connection mysql_connect($server$user$pass
     or die (
    "Could not connect to server ... \n" mysql_error ());
     
    mysql_select_db($db
     or die (
    "Could not connect to database ... \n" mysql_error ());

            
    // get results from database
            
    $result mysql_query("SELECT title,summary FROM announcements LIMIT 1"
                    or die(
    mysql_error());  

            
    // loop through results of database query, displaying them in the table
            
    while($row mysql_fetch_array$result )) {
                    
    echo 
    "
          <form action=\""
    ; echo $_SERVER['REQUEST_URI']; echo "\" method=\"POST\" id=\"form2\" name=\"form2\">
          <a href=\"javascript:void(0);\" onClick=\"document.form2.submit();\" />Dismiss</a>
          <input type=\"hidden\" name=\"form2\" />
          </form>
          <h2>" 
    $row['title'] . "</h2>
          <p>" 
    $row['summary'] . "</p>";
            } 
    ?>

    Now my issue is with the form submit. Once they click the "Dismiss" button, they immediately go back to the current page, but if they haven't gone to any page except the home page. On any browser, after they hit "Dimiss", the see the "back button" on their browser. I don't want users to see that because they might be thinking that there's a code going around and screwing with their account. Now how would I got about? Would it be jquery or javascript that makes the announcement bar fadeout without refreshing the page and not showing the "back button" on any browser?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    As soon as you make mention of things like clicking dismiss, that is now an event. That makes this an issue with the client code, not an issue with the server code.
    So yes, this is a javascript issue, not a PHP one.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    75
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    As soon as you make mention of things like clicking dismiss, that is now an event. That makes this an issue with the client code, not an issue with the server code.
    So yes, this is a javascript issue, not a PHP one.
    Ok, thanks. I fixed it. Now it's working.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •