我希望在更新记录时出现警告框

时间:2014-09-22 07:00:38

标签: php

我有php文件,我需要检查变量是否为空,然后更新表。除了警报,一切正常。

<?php




$con=mysql_connect("localhost","root","");


mysql_select_db("sg",$con);
  error_reporting(0);
$result1=mysql_query("select DeclarationNo,DeclarantReferenceNo from sg_report where DeclarationNo='$dec' OR DeclarantReferenceNo='$dec'");
if(isset($_POST['myText'])){ $cn = $_POST['myText']; } 
if(isset($_POST['myText1'])){ $dec = $_POST['myText1']; }
if(isset($_POST['tb3'])){ $rem = $_POST['tb3']; }


I want a alert box to come up when records are updated

 if( !empty($dec) && !empty($rem)  ){

$result=mysql_query("update sg_report set CreditNoteStatus='$cn',Remarks='$rem' where DeclarationNo='$dec' OR DeclarantReferenceNo='$dec'");
echo "<script type='text/javascript'>alert('Updated successfully!');</script>";
} 

如果未输入所有值,我想要一个警告框

if(empty($dec) || empty($rem) ) {  
   echo "<script type='text/javascript'>alert(\"Please enter all Values\");window.location=\"view3.php\";</script>";

    } 





?>

2 个答案:

答案 0 :(得分:0)

if(isset($_POST['myText']) && isset($_POST['myText1']) && isset($_POST['tb3']))
{
$result=mysql_query("update sg_report set CreditNoteStatus='$cn',Remarks='$rem' where DeclarationNo='$dec' OR DeclarantReferenceNo='$dec'");
if($result)
{
    echo "<script type='text/javascript'>alert('Updated successfully!');</script>";
}
}
else
{
echo "<script type='text/javascript'>alert(\"Please enter all Values\");window.location=\"view3.php\";</script>";
}

答案 1 :(得分:-1)

试试这个

if(trim($_POST['myText'])!=''&&trim($_POST['myText1'])!=''&&trim($_POST['tb3'])!='')
{
    $result=mysql_query("update sg_report set CreditNoteStatus='$cn',Remarks='$rem' where DeclarationNo='$dec' OR DeclarantReferenceNo='$dec'");
    if($result)
    {
        echo "<script type='text/javascript'>alert('Updated successfully!');</script>";
    }
}
else
{
    echo "<script type='text/javascript'>alert(\"Please enter all Values\");window.location=\"view3.php\";</script>";
}