Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 39

Thread: Alerts

  1. #21
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    334
    Tokens
    0

    Default

    There is no SQL needed with it.

    PHP Code:
    <head>
    <script language="javascript" type="text/javascript"> alert(' 
    <? echo(file_get_contents("alert.txt"); ?>
    '); </script>
    is the code.

  2. #22
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Have you created alert.txt and CHMOD'd it?

    - Dan

  3. #23
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    334
    Tokens
    0

  4. #24
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Not sure then.

    - Dan

  5. #25
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?
    echo "<script language='javascript' type='text/javascript'> alert('";
    include 
    "alert.txt";
    echo 
    "'); </script>";
     
    ?>
    That should work.

  6. #26
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    334
    Tokens
    0

    Default

    w00t it worked thanks

    Now, this will probably be simple, but I need a simple php script or whatever that will write a new message to the alert.txt file by typing it in a text box or something.

    Rob

  7. #27
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    I won't do the HTML because its to easy, but heres the php

    PHP Code:
    <?
    if ($_SERVER['REQUEST_METHOD'] != 'GET'){
    $alert$_POST['alert'];
    $file fopen("alert.txt""w+");
    fputs($file$alert);
    fclose($file);
    echo 
    "'$alert' has been broadcasted!";
    ?>
    Create a form with a text box called alert

    Hope this helped

  8. #28
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Tomdarkness2
    *sigh*
    Change the Username password and database name. Also you might want to chage the bit about Message from ....
    Run this SQL:

    Code:
    CREATE TABLE `alert` (
    `ID` INT( 4 ) NOT NULL AUTO_INCREMENT ,
    `message` TEXT NOT NULL ,
    `active` CHAR( 1 ) NOT NULL ,
    PRIMARY KEY ( `ID` )
    ) TYPE = MYISAM ;
    Alert.php :

    PHP Code:
    <?
    $dbName 
    "yourdatabasename";
    $dbUser "dbusername";
    $dbPass "dbpass";
    // Connect
    mysql_connect ("localhost""$dbUser""$dbPass");
    mysql_select_db ("$dbName");

    // Get Alert
    $alertQuery mysql_query("SELECT * FROM alert WHERE active='Y'");
    if(
    mysql_num_rows($alertQuery) =="1"){
      
    $alertData mysql_fetch_array($alertQuery);
      
      if(
    $_COOKIE[$alertData[ID]] !="Y"){
        
    $y "Y";
        
    setcookie($alertData[ID], $y);
        Echo
    "
        <script language='javascript'>alert('
    $alertData[message]');</script>";
      }
    }


    Echo
    "<META HTTP-EQUIV='refresh' content='60;URL=alert.php'>";
    Echo
    "$_COOKIE[$alertDataID]"
    ?>
    Smack this file in a secure directory or add some nifty PHP codeing to it your self:

    PHP Code:
    <?
    $dbName 
    "dbname";
    $dbUser "user";
    $dbPass "pass";
    // Connect
    mysql_connect ("localhost""$dbUser""$dbPass");
    mysql_select_db ("$dbName");

    switch(
    $_GET['act']){
    default:
      
    // Alert Data
      
    $alertQuery mysql_query("SELECT * FROM alert WHERE active='Y'");
      
    $alertData mysql_fetch_array($alertQuery);
      
      if(
    $alertData[message] !=""){
        
    $Var ="<u>Current Active Alert</u>: $alertData[message] [<a href='alert.php?act=deactivate'>Deactivate</a>]";
      }

      Echo
    "<center><b>Alert Script Control Panel</b></center>
      <u>NOTE:</u> You can only have one alert at one time. Once you want people to
      stop being alerted, you will have to deactive it below. Creating a new alert
      will delete the old one.<br>
      
      
    $Var
      
      <hr width='100%' height='1' color='#000000' shade='no'>
      
      <form method='post' action='alert.php?act=create'>
      Message:<br>
      <textarea name='message' cols='30' rows='6'>Keep the message short</textarea><br>
      <input type='submit' value='Create'>
      </form>"
    ;
    break;

    case
    "create":
      
    $message "From your sites name DJ: "$_POST['message'];
      
      if(empty(
    $message)){
        Echo
    "<b>Error:</b> Please fill out the message.";
        exit;
      }
        
    mysql_query("UPDATE alert SET active ='N'");
        
    mysql_query("INSERT INTO alert (message,active) VALUES ('$message','Y')");
        
        Echo
    "<b>Alert Added Sucessfully</b><br>
        All other alerts have been deactivated. All users will recieve this alert
        once, until you deactivate it."
    ;
    break;

    case
    "deactivate":
      
    mysql_query("UPDATE alert SET active ='N'");
      Echo
    "<b>Alerts Deactivated</b><br>
      All previous alerts have been deactivated."
    ;
    break;

    }
    ?>
    Or you could do it that way *sigh*

    Will that also only send the alert once?

  9. #29
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Luckyrare
    Or you could do it that way *sigh*
    Its better because it dosent keep showing the alert to the vister everytime the alert.php refreshes lol

  10. #30
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    334
    Tokens
    0

    Default

    Thanks.

    But it aint working.

    http://www.wackyhabbo.co.uk/hab-tastic/alerts/alert.php is just blank and shows no alert

    and http://www.wackyhabbo.co.uk/hab-tast...rts/script.php becomes blank when you have typed a message.

    Any suggestions anyone?

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

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