代码如下
 <?php
 $con = mysql_connect("localhost","root","199324");
 if($con)
 {
         mysql_select_db("test",$con);
         $sql = "CREATE TABLE  temp
         (
                 id int(5) not null auto_increment primary key,
                 name char(10) not null default ' ',
                 sex char(2) not null default '男',
                age int(3) not null default 0 ,
                 work char(10) not null default ' ',
                 city char(10) not null default ' ',
                 other char(50) not null default ' '
         )";
         $do = mysql_query($sql,$con);
         if($do)
         {
                 echo "成功在test数据库中创建表!";
         }
         else  echo "建表错误!";
 }else "连接服务器出错!";
 ?>
 <?php
 $con = mysql_connect("localhost","root","199324");
 mysql_select_db("test");
 mysql_query("SET NAMES GB2312");
 $sql = 'SELECT COUNT(*) FROM temp';
 $result = mysql_query($sql);
 $num = mysql_fetch_array($result);
 echo "当前表中记录数为:".$num[0]."<p>";
 $insert = "INSERT INTO temp('id', 'name', 'sex', 'age', 'work', 'city', 'other') VALUES (1, 'di', 'man', 480, 'west', 'west', 'boss')";
 
$re = mysql_query($insert);
 if($re)
 {
         echo "成功插入数据<p>最后插入的类容为:<p>";
         $id = mysql_insert_id();
     $sql = "SELECT * FROM temp WHERE id = $id";
         $result = mysql_query($sql);
         $content = mysql_fetch_row($result);
         print_r($content);
 }else
 echo "插入失败";
 ?>
 ------------------------------------------------------------------------------------------------------------------------------------------------》》》》
 第一个程序创建一个表
 第二个程序试图在表中添加一个记录
 可以成功创建表 但是记录总是添加不成功是什么原因呢?