dongqu2863 2012-06-22 09:29
浏览 33
已采纳

在表单中显示错误消息

I want to display error message or alert message after checking the condition.

here is my code

    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();
}


    }
    }
                }

?>

and after this i have placed my html form

<!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>

When the user entered companyemail is already exists it should display the alert message just below the company email field in the form. But now its displaying in the starting of the page. I dont know what to use and how to use. Please suggest

  • 写回答

2条回答 默认 最新

  • dongsi4815 2012-06-22 09:31
    关注
    $msg = "";
    if($row['count(CompanyEmail)'] > 0)
                        {
    
    
        $msg = "This E-mail id is already registered ";
    }
    

    and HTML

    <input type="text" name="CompanyEmail" style="width:230px; height:20px;" /><br />
    <?php echo $msg; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办