There is no SQL needed with it.
is the code.PHP Code:<head>
<script language="javascript" type="text/javascript"> alert('
<? echo(file_get_contents("alert.txt"); ?>
'); </script>
There is no SQL needed with it.
is the code.PHP Code:<head>
<script language="javascript" type="text/javascript"> alert('
<? echo(file_get_contents("alert.txt"); ?>
'); </script>
Have you created alert.txt and CHMOD'd it?
- Dan
Not sure then.
- Dan
That should work.PHP Code:<?
echo "<script language='javascript' type='text/javascript'> alert('";
include "alert.txt";
echo "'); </script>";
?>
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
I won't do the HTML because its to easy, but heres the php
Create a form with a text box called alertPHP Code:<?
if ($_SERVER['REQUEST_METHOD'] != 'GET'){
$alert= $_POST['alert'];
$file = fopen("alert.txt", "w+");
fputs($file, $alert);
fclose($file);
echo "'$alert' has been broadcasted!";
?>
Hope this helped![]()
Or you could do it that way *sigh*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:
Alert.php :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 ;
Smack this file in a secure directory or add some nifty PHP codeing to it your self: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]"
?>
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;
}
?>
Will that also only send the alert once?
Its better because it dosent keep showing the alert to the vister everytime the alert.php refreshes lolOriginally Posted by Luckyrare
Or you could do it that way *sigh*![]()
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?![]()
Want to hide these adverts? Register an account for free!