alert boxes in php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tom456
Forum Newbie
Posts: 22
Joined: Fri Aug 15, 2008 2:38 am

alert boxes in php?

Post by tom456 »

hi!
i want modify the following script... if somebody sends a song by writting the song name in the textbox and presses the button, then the alert message will appear center of the page (e.g. TNX! Song sent successfully) instead of going to other page... like this: echo "<meta http-equiv=refresh CONTENT=5;URL=index.htm>";

here's the code:

Code: Select all

<head>
<link rel="stylesheet" href="style.css">
<title>List</title>
</head>
<body>
<font>
<?php
$smiley = 1;
$ip = getenv(REMOTE_ADDR);
$fail=@file("ip.txt");
$ex=explode("¤",$fail[0]);
for($i=1;$i<count($ex);$i++)
{
$osa=explode("|",$ex[$i]);
}
$viimane_saatmisaeg=$osa[1];
$postiaeg=1800; 
$praegu=time();
$vaheaeg = $viimane_saatmisaeg + $postiaeg;
if($osa[0]=="$ip"){
if ($vaheaeg > $praegu) {
$temp1=liiga;
}}
 
if ($temp1==liiga) { echo"You have already sent a song too us.."; }
elseif (!$nimi) {echo '<meta HTTP-EQUIV="refresh" CONTENT="0;URL=viga.php">';}
else {
$nimi = str_replace ('<', '<', $nimi);
$nimi = str_replace ('>', '>', $nimi);
$aeg =date('d.m.Y - G:i');
 
$uus_sisu = wordwrap($sisu, 49, "<br>", 1);
 
$uus_sisu ="<center><table width=\"100%\" height=\"42\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-bottom: 1 double #000000; border-top: 1 double #000000; border-left: 1 double #000000; border-right: 1 double #000000\">
  <tr>
      <td width=\"39%\" height=\"21\" bgcolor=\"#DFDFDF\"> <font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><B>&raquo;</B></font>
        <font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$nimi</font></font></td>
    <td width=\"1%\" bgcolor=\"#DFDFDF\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$aeg</font></td>
  </tr>
  <tr>
        <font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$uus_sisu</font></td>
  </tr>
</table></center>";
if ($smiley == 1) {
$uus_sisu = str_replace(":)", "<img src=\"images/smile.gif\">",$uus_sisu);
$uus_sisu = str_replace(":(", "<img src=\"images/sad.gif\">",$uus_sisu);
$uus_sisu = str_replace(":o", "<img src=\"images/shocked.gif\">",$uus_sisu);
$uus_sisu = str_replace("8)", "<img src=\"images/cool.gif\">",$uus_sisu);
$uus_sisu = str_replace(":-[", "<img src=\"images/embarassed.gif\">",$uus_sisu);
$uus_sisu = str_replace("<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>", "***",$uus_sisu);
}
 
$cont = join ( '', file ("sisu.txt"));
$open = fopen ("sisu.txt", "r+");
fwrite ($open, "$uus_sisu\n");
fwrite ($open, $cont);
fclose($open);
$time = time();
$fp = fopen("ip.txt",  "a"); 
fputs($fp, "¤$ip|$time"); 
fclose($fp); 
 
echo "<HTML>";
echo "<HEAD>";
echo "<meta http-equiv=refresh CONTENT=5;URL=index.htm>";
echo "<TITLE>List</TITLE>";
echo "</HEAD>";
echo "<BODY>";
echo "<left>
  <table width='100%' height='30' border='0' style='border-top: 1 double #000000; border-bottom: 1 double #000000; border-left: 1 double #000000; border-right: 1 double #000000'>
    <tr>
      <td bgcolor='#DFDFDF'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><left>
          TNX! Song sent successfully!</left>
        </font></td>
    </tr>
  </table>
</center>";
echo "</BODY>";
echo "</HTML>";
}
?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: alert boxes in php?

Post by califdon »

You do realize that there is no PHP code by the time the browser sees it, don't you? You can't write PHP code that reacts to what a user does, because all the PHP is executed at the server before the page is sent to the browser. You need client-side scripting. (Hint: Javascript)
Post Reply