新手提问。。。直接看吧。。。
我是把有mysql的代码独立在in.php页面,in.php代码如下:
<?php date_default_timezone_set('PRC'); $sj = date("Y-m-d H:i:s"); $sql = mysql_connect("127.0.0.1","root","kingmo"); mysql_query('$sql'); if (!$sql){ die('数据连接失败,原因:'.mysql_error()); } mysql_select_db("yang",$sql); $a_os = mysql_query("SELECT os FROM os"); if (!$a_os){ die('数据查询失败,原因:'.mysql_error()); } $os = mysql_fetch_array($a_os); if($go==1) mysql_select_db("yang",$sql); $a_lr = "SELECT xinxi FROM name, old, add, pj"; mysql_query($a_lr,$sql); $lr = "INSERT INTO Persons (name, old, add, pj) VALUES ('$_POST[name]','$_POST[old]','$_POST[add]','$_POST[pj]')"; if (!mysql_query($lr,$sql)){ die ('发生错误了囧,代码:'.mysql_error()); } echo "录入成功拉!!!"; mysql_close($sql); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"></head><body><form action="luru.php?go=1" method="post">姓名:<input type="text" name="name" />年龄:<input type="text" name="old" />地址:<input type="text" name="add" />评级:<input type="text" name="pj" /><input type="submit" /></form><?php include 'include/in.php'; ?></body></html>