求大神们帮忙了!!!
我想先判断表单部分的内容是否为空执行JS部分,如果为空就焦点为空的元素。如果不为空再去执行PHP部分的内容。
1、这是.PHP部分
$a = "UPDATE test SET user= $_POST[user] WHERE id = $_POST[id]";
$b = "SELECT id FROM test WHERE id = $_POST[id]";
if (IsEmpty()=true){
$ljmysql = mysql_connect("localhost","root","");
if (!$ljmysql){
die('mysql不能连接!'.mysql_error());
}
$ljdb = mysql_select_db("007c",$ljmysql);
if (!$ljdb){
die('不能打开datebase!'.mysql_error());
}
mysql_query('set names gbk');//根据字段的编码不同,要统一。
$result = mysql_query($b,$ljmysql);
$num = mysql_num_rows($result);
if ($num == 0){
echo '文件号'.$_POST[id].'不存在';
}
else {
mysql_query($a,$ljmysql);
echo '数据更新成功';
}
mysql_close($ljmysql);
}
?>
2、这是.JS部分
function IsEmpty(){
var a=document.getElementById("id").value;
if(a==""){
alert ("文件号不能为空"+"\n"+"请加上");
id.focus();
return false;
}
else{
return true;
}
}
3、这是.html部分
<html>
<head>
<script type="text/javascript" src="update.js"></script>
<form action = "update.php" method = "POST">
</form>
</head>
<body>
<form action = "update.php" onSubmit="return IsEmpty()" method = "POST">
<table>
<tr><td><label for = "id">文件号:</label></td><td><input type = "text" size="8" name = "id" /></td></tr>
<tr><td><label for = "user">姓名:</label></td><td><input type = "text" size = "8" name = "user" /></td></tr>
<tr><td><input type = "submit" name = "submit" value = "提交更新" />
<input type = "reset" name = "reset" value = "重新填写" /></td></tr>
</table>
</form>
</body>
</html>
运行以后提示的错误
Fatal error: Can't use function return value in write context in D:\Program Files\PHP LIST\wamp\www\update.php on line 19