how to make the error message pop up?!

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
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

how to make the error message pop up?!

Post by masterphp »

I have designed a simple php code to handle "leave message board" function, there are two fields must be entered by user-"Username" and "Message Content", if either one of those field is empty, then a error message box should be pop up stating that"those two fields must be enterd", for testing purpose, I leave those two field blank and when I click "Submit" button, then error message doesn't pop up, so can anyone help me with that? Thanks! The following is my code:

Code: Select all

<!--add.php--------------->
<?php
    require_once("sys_conf.inc");
 
    //decide whether message and username is empty
    $errorm="";
     if (!isset($message) or $message=="" or !isset($name) or $name=="") 
    { 
        $errorm="<font color=red></font>* Must be entered"; 
    } 
    else 
    { 
        
        $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);         
        mysql_select_db($DBNAME);               
    
        $space = "&nbsp;"; 
        $time = date("YmdHi"); 
        $ip=$REMOTE_ADDR; 
        $message=StripSlashes($message);        
        $message=htmlspecialchars($message); 
        $message=nl2br($message);           
 
        $guestcontent = "<tr><td><font color=#AB00E1>Message Content:</font><br>$message"; 
        $guestcontent=$guestcontent."<br><font color=#6633FF>Username:  </font>$name"; 
        if ($email !="") 
            $guestcontent=$guestcontent."<br><font color=#9900CC>Email:</font><a href=\"mailto:$email\">$email</a>"."$space"; 
        if ($Domain !="") 
            $guestcontent=$guestcontent."<font color=#9900CC>Domain"; 
        if ($Team !="") 
            $guestcontent=$guestcontent."<br><font color=#0000FF>Team:</font>";
        $guestcontent=ereg_replace(chr(10),"",$guestcontent); 
        $guestcontent=$guestcontent."<hr size=1></td></tr>\n"; 
 
        
        $str="insert into guestbook (time,ip,name,domain,team,email,message,content,is_delete)";
        $str=$str."values('$time','$ip','$name','$domain','$team','$email','$message','$guestcontent','n')";
        //echo $str;
        $result=mysql_query($str,$link_id);     
        mysql_close($link_id);   
    }
?>
<html> 
    <head> 
        <title>Search
            </title> 
    <style> 
        <!-- 
            A:link {text-decoration: none ; color:0000ff} 
            A:visited {text-decoration: none; color:004080} 
            A:active {text-decoration: none} 
            A:hover {text-decoration: underline; color:ff0000} 
            BODY {FONT-SIZE:10pt} 
            TH {FONT-SIZE:10 pt} 
            TD {FONT-SIZE: 10pt} 
            TEXTAREA 
            { 
            FONT-FAMILY: "Time News Roman"; 
            FONT-SIZE: 10pt; 
            }
        --> 
    </style> 
</head>
<body bgcolor=#FFFFFD> 
<center>
    <?php include  "head.html"?>
    <h2>Post Message</h2>
    <table width="68%" border="1" cellpadding="3" cellspacing="0" bordercolor="#E3E3E3"> 
        <form method="POST" action="add.php"> 
        <?php
 
        if ($errorm) 
        { 
            echo "<tr>"; 
            echo "<td colspan=3 height=32> "; 
            echo "$errorm"; 
            echo "</td>"; 
            echo "</tr>"; 
        } 
        ?>
        <tr>    
            <td width="32%" bgcolor="#F0F0F0"><font color="#000000">*Username<font color="#FF0033"></font></font></td> 
            <td colspan="2" width="78%" bgcolor="#F0F0F0"><font color="#00FF00">    
                <input type="text" name="name" size="40"> 
                </font></td> 
        </tr> 
        <tr>    
            <td width="22%" height="29">Domain:</td> 
            <td colspan="2" height="29" width="78%">    
                <input type="text" name="domain" size="40"> 
            </td> 
        </tr> 
        <tr>    
            <td width="22%" height="27" bgcolor="#F0F0F0">Team:</td> 
            <td colspan="2" height="27" width="78%" bgcolor="#F0F0F0">  
                <input type="text" name="team" size=40">
            </td> 
        </tr> 
        <tr>    
            <td width="22%" height="20">Email:</td> 
            <td colspan="2" height="20" width="78%"><font color="#00FF00">  
                <input type="text" name="email" size="40"> 
                </font></td> 
        </tr> 
        <tr>    
            <td colspan="3" valign="middle" align="left">   
                <div align="center"><font color="#000000">*Leave Message</font><font color="#FF0033"></font><font color="#00FF00"><br> 
                <textarea rows="6" name="message" cols="55" wrap="VIRTUAL"></textarea> 
                </font></div> 
            </td> 
        </tr> 
        <tr bgcolor="#F0F0F0">  
            <td colspan="3" height="24">    
                <div align="center"><font color="#00FF00">  
                <input type="submit" value="Submit" name="ok"> 
                &nbsp;&nbsp;&nbsp;  
                <input type="reset" value="Clear" name="cencel"> 
                </font>
            </td> 
        </tr> 
        </form> 
    </table>    
    
    </center> 
    </body> 
</html>
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

Re: how to make the error message pop up?!

Post by masterphp »

Actually I figure it out that the following one line of PHP code can make the "pop up window error message" happen, but I got syntax error for that, so can anyone help me with this? how can I make a pop up window stating the error message? Thanks!

Code: Select all

$errorm="<li><a target="_blank"* Field must be entered"</a></li>;
Post Reply