<?php
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("school") or die(mysql_error());
if ($_POST['submit']){
                                       
    $sql = "INSERT INTO student (id,name) VALUES ($id,'$name')";                   
    $result = mysql_query($sql);                                                                     
    } 
    //删除
  if($_POST['delete']){
    $sql ="delete from student where id = $id";
    $result = mysql_query($sql);
    }
    //修改
   if($_POST['update']){
    $sql = "update student set name='$name' where id = $id";
    $result = mysql_query($sql);
    }
    $result = mysql_query("select * from student",$db);//查询
echo "<table border=1>\n";                                       
    echo "<tr><td>学号</td><td>姓名</td>";                                                      
    echo "</tr>\n";                                                  
                                                           
while ($myrow = mysql_fetch_row($result)){                                                                
    printf("<tr><td>%s</td><td>%s</td>", $myrow[0], $myrow[1]);
    }                                                                
echo "</table>\n"; 
?>
<html>
<form action="department.php" name="">
   学号<input type="text" name="id"/> <br/>
   姓名<input type="text" name="name"/><br/>
   <input type="submit" value="添加" name="$_POST['submit']"/>
   <input type="submit" value="删除" name="$_POST['delete']"/>
   <input type="submit" value="修改" name="$_POST['update']"/>
</form>
</html>

解决方案 »

  1.   

    <html>
    <form action="department.php" name="">
       学号<input type="text" name="id"/> <br/>
       姓名<input type="text" name="name"/><br/>
       <input type="submit" value="添加" name="$_POST['submit']"/>
       <input type="submit" value="删除" name="$_POST['delete']"/>
       <input type="submit" value="修改" name="$_POST['update']"/>
    </form>
    </html>
    改为
    <html>
    <form action="department.php" name="">
       学号<input type="text" name="id"/> <br/>
       姓名<input type="text" name="name"/><br/>
       <input type="submit" value="添加" name="submit"/>
       <input type="submit" value="删除" name="delete"/>
       <input type="submit" value="修改" name="update"/>
    </form>
    </html>这样$_POST['submit']才有值
      

  2.   

    我又看了下  你这个代码问题比较多首先,name="$_POST['submit']"  如果你是希望name里边能用到接收到的值,那么必须在html页面里边用name="<?php echo $_POST['submit'];?>"才能调用php的变量其次,if ($_POST['submit']) 没有检测通过. 因为只有当表单含有name="submit"的元素时 PHP才会有$_POST['submit'];这里边的问题你好好揣摩下... PHP与HTML的区别与联系 明白了这个后边才能继续做下去.