我有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>";
}
?>
什麼是錯的警報,以及爲什麼你不使用Ajax進行交互? – Justinas 2014-09-22 07:03:31
回聲警告線本身工作正常。檢查你的查詢是否實際運行,並使用'var_dump()'來檢查你的變量是否真的包含你的想法。 – 2014-09-22 07:16:07
備註:'mysql_ *'函數已棄用,不應用於編寫新代碼。他們將從未來版本的PHP中刪除,然後您的代碼將停止工作。 [使用'mysqli_ *'或PDO代替](http://php.net/manual/de/mysqlinfo.api.choosing.php)。此外,您打開SQL注入。 – 2014-09-22 07:19:19