问题如下:
有三个页面:index.php / class.php / config.php
页面内容分别如下:
config.php:<?php
$con=mysql_connect('localhost','root','admin');
?>
class.php:<?php
$un=$_post['UserName'];
$ua=$_post['UserAge'];class controldata
{
/////////////////////////////读取表中数据///////////////////////////////
function connectdata($table,$sql,&$con)
{
if(!$con)
 {
die('Could not connect:'.mysql_error());
 }
mysql_select_db($table,$con);
$result=mysql_query($sql);
return $result;
}
/////////////////////////////更新表中数据///////////////////////////////
function update($x,$y,$z,&$con)
{
if($x=="action" and $y!=="" and $z!=="")
 {
 mysql_select_db("huaxin_db",$con);
 $sql="update hx_user set UserAge = '$z' where UserName = '$y' ";
 mysql_query($sql);
 mysql_close($con);
 }
}
}
?>
index.php:<?php
require("class.php");
require("config.php");$cd=new controldata();  //调用类函数
//更新表中数据
echo $br;
mysql_select_db("huaxin_db",$con);
$result=mysql_query("select * from hx_user order by hx_id desc");
while($row=mysql_fetch_array($result))
{
$uname=$uname."<option value=".$row['UserName'].">".$row['UserName']."</option>";
}
mysql_close($con);
echo "<form method=post name=form1 onsubmit=".$cd->update('action',$un,$ua,$con).">UserName:<select name=UserName>".$uname."</select>UserAge:<input type=text name=UserAge id=UserAge><input type=submit value=提交></form>";
出现的问题是:
当打开index.php页面时,好像就开始调用执行controldata类中的update()函数;
在index.php页面中明明是onsubmit时才会执行,为什么事实却是打开页面就会执行update()方法呢???