2012-06-22 176 views
0

我想在检查条件后显示错误消息或警报消息。在窗体中显示错误消息

这里是我的代码

session_start(); 

    $plan = @$_GET['plan']; 
    $plan = +$plan; 
    include('connect.php'); 

      If (isset($_POST['submit'])) 
      { 
      $CompanyName = $_POST['CompanyName']; 

      $CompanyEmail = $_POST['CompanyEmail']; 
      $CompanyContact = $_POST['CompanyContact']; 
      $CompanyAddress = $_POST['CompanyAddress']; 

      $RegistrationType = $_POST['RegistrationType']; 
      $Plans = $_POST['plan']; 
      $Status = "Active"; 
    $query1 = "select count(CompanyEmail) from ApplicationRegister where CompanyEmail = '$CompanyEmail'" ; 
    $result1 = mysql_query($query1) or die ("ERROR: " . mysql_error()); 
    //$result1 = mysql_result($query1, 0, 0); 
    //echo $result1; 
    while ($row = mysql_fetch_array($result1)) 

       { 
        //$companyemail = $row['CompanyEmail']; 
        //if($companyemail != '' || $companyemail!= 'NULL') 
        //{ 
         if($row['count(CompanyEmail)'] > 0) 
         { 


     echo "This E-mail id is already registered "; 
    } 
    else 
    { 

    $sql = "INSERT INTO ApplicationRegister(CompanyName, CompanyEmail, CompanyContact, CompanyAddress, RegistrationType, ApplicationPlan, ApplicationStatus, CreatedDate) VALUES ('$CompanyName', '$CompanyEmail', '$CompanyContact', '$CompanyAddress', '$RegistrationType', '$Plans', '$Status', NOW())"; 
$result = mysql_query($sql) or die(mysql_error()); 

$id = mysql_insert_id(); 

$_SESSION['application_id'] = $id; 


//if(isset($plan == "trail")) 
if($plan == "trail") 
{ 

header("Location: userRegister.php?id=$id"); 
exit(); 
} 
else 
{ 
    header("Location : PaymentGateway.php"); 
    exit(); 
} 


    } 
    } 
       } 

?> 

,并在这之后我已经把我的HTML表单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<link href="style.css" rel="stylesheet" type="text/css" /> 


<title>Welcome</title> 
</head> 
<body> 
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
       <td><h2><br /> 
        Application Registration</h2> 
        <p>&nbsp;</p></td> 
       </tr> 
       <tr> 
       <td><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return Validate();"> 
       <input type="hidden" name="plan" value="<?php echo $plan ?>"/> 
    Company Name: 
     <input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br /> 
    Company E-mail : 
    <input type="text" name="CompanyEmail" style="width:230px; height:20px;" /><br /><br /> 
    Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br /> 
    Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br /> 
    Select Your Registration Type : <br /><br /> 
Trail: <input type="radio" name="RegistrationType" value="Trail" /><br /> 
            Paid<input type="radio" name="RegistrationType" value="Paid" /><br /><br /> 

    <input type="hidden" name="form_submitted" value="1"/> 
    <input type="submit" value="REGISTER" name="submit" /> 



</form> 


    </td> 
       </tr> 

      </table> 

当用户输入companyemail已经存在,它应该显示略低于公司的电子邮件警报消息领域的形式。但现在它显示在页面的开头。我不知道该使用什么以及如何使用。请建议

回答

2
$msg = ""; 
if($row['count(CompanyEmail)'] > 0) 
        { 


    $msg = "This E-mail id is already registered "; 
} 

和HTML

<input type="text" name="CompanyEmail" style="width:230px; height:20px;" /><br /> 
<?php echo $msg; ?> 
+0

Miqdad阿里:非常感谢你。这是我想要的。但是如何使这个字体变成红色。 – user1321271

+0

$ msg =“此电子邮件ID已注册”; –

+0

非常感谢。它为我工作。万分感谢 – user1321271

0

这个查询将返回只有一个记录。因此,它不需要使用while循环

$query1 = "select count(CompanyEmail) from ApplicationRegister where CompanyEmail = '$CompanyEmail'" ; 
$result1 = mysql_query($query1) or die ("ERROR: " . mysql_error()); 

试试这个,

$query1 = "select count(CompanyEmail) from ApplicationRegister where CompanyEmail = '$CompanyEmail'" ; 
    $result1 = mysql_query($query1);  
    $row = mysql_ferch_array($result1); 
if($row['count(CompanyEmail)'] > 0){ 
    error message 
}else{ 
insert uery 
}