如果你手上有php的教材书,那么这样问题的答案可以自己找到,一般每本PHP书上都有数据库操作这一篇章。
或者你可以到网上搜索,你可以选择baidu.com。:)

解决方案 »

  1.   

    只做简单的一样是可以做出来的但是我要在同一个页面做增删改查提交的时候都会执行<?php ?>里面的代码不晓得该怎么去判断点的添加就做添加的代码
    或者其他的
      

  2.   

    在每个form里加个隐藏控件
    比如添加的form
    <form name="form1" action="">
    ......
    <input name="t_operation" value="add">
    ......
    </form>修改的form
    <form name="form1" action="">
    ......
    <input name="t_operation" value="edit">
    ......
    </form>然后提交给本页的时候,根据 $_POST['t_operation']的值来判断是做添加、修改或删除操作
    $operation = $_POST['t_operation'];
    switch($operation)
    {
        case "add":
             add();
             break;
        case "edit":
             edit();
             break;
        case "del":
             del();
             break;
    }
      

  3.   

    刚忘了隐藏的要加个type,="hidden",呵呵:
    <input type="hidden" name="t_operation" value="add"> 
      

  4.   

    在页面初始化的时候
    执行$sub = $_REQUEST['sub'];会报错
    只有在提交的时候才不会报错
    隐藏表单也不行
      

  5.   


    初始页面填写这个判断
    if($_POST['process']=="action")
    {
       //里面写你提交的程序
    }
    //在form添加多隐藏input
    <form>
    <input type="hidden" id="process" name="process" value="action">
    </form>
      

  6.   

    其实你可以隐藏域 和 get参数来实现
    我前段时间做的论坛就是这样实现的 
      

  7.   

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Accall » Call</title><style type="text/css">
    <!--
    .STYLE1 {color: #FF0000}
    -->
    </style>
    <script type="text/javascript">   
            //全局变量   
            var i=0;   
            //添加行   
            function addMyRow(){   
                var mytable = document.getElementById("mybody");   
               var mytr = mytable.insertRow();   
                mytr.setAttribute("id","tr"+i);   
                var mytd_1=mytr.insertCell();   
                var mytd_2=mytr.insertCell();   
               var mytd_3=mytr.insertCell();
       var mytd_4=mytr.insertCell();
       var call_name= document.getElementById("call_name").innerHTML; 
       var first_callee= document.getElementById("first_callee").innerHTML;   
       var sec_callee= document.getElementById("sec_callee").innerHTML;   
                mytd_1.innerHTML="<input type='text' id='call_name' name='call_name"+i+"' value='"+call_name+"'/>";   
                mytd_2.innerHTML="<input type='text' id='first_callee' name='first_callee"+i+"' value='"+first_callee+"'/>";   
                mytd_3.innerHTML="<input type='text' id='sec_callee' name='sec_callee"+i+"' value='"+sec_callee+"'/>";
    mytd_4.innerHTML="<input name='add' type='submit' id='add' value='保存' /><input name='del' type='submit' id='del' value='删除' />"; 
                i++; 
      
            }   
            </script>  
    <div>
    <?php
    require "../includes/init.php";
    //这里是PHP代码
    $sql = "SELECT * FROM `callback_book`";//需要执行的SQL语句(这里是浏览数据功能)
    $result = $db2->getAll($sql);
    if($_POST['modify']){
    $id=$_POST['id'];
    $call_name=$_POST['call_name'];
    $first_callee=$_POST['first_callee'];
    $sec_callee=$_POST['sec_callee'];$sql=" UPDATE callback_book SET call_name = '".$call_name."',first_callee = '".$first_callee."',sec_callee = '".$sec_callee."' WHERE id = ".$id;
     $result = $db2->query($sql);
     if($result){
    echo "<script language='javascript'>"; 
     echo " location='index.php';"; 
      echo "</script>";
    }else echo "提交失败,请重启提交!";
    }
    if($_POST['del'])
    {
    $id=$_POST['id'];
     $sql = "delete from callback_book where id=".$id;
    $result = $db2->query($sql);
    if($result){
      echo "<script language='javascript'>"; 
      echo " location='index.php';"; 
      echo "</script>";
    }
    }
    if($_POST['add']){
    if(!is_decimal($_POST['first_callee'])){
    echo "<script>window.location.href='index.php?err=主叫格式错误&u=".$_GET['u']."&p=".$_GET['p']."';</script>";
    exit;
    }if(!is_decimal($_POST['sec_callee'])){
    echo "<script>window.location.href='index.php?err=被叫格式错误&u=".$_GET['u']."&p=".$_GET['p']."';</script>";
    exit;
    }
     $call_name=trim($_POST['call_name']);
     $first_callee=trim($_POST['first_callee']);
     $sec_callee=trim($_POST['sec_callee']);
     $sql="insert into callback_book(id,call_name,first_callee,sec_callee,call_time) values('','".$call_name."','".$first_callee."','".$sec_callee."',now())";
     if($db2->query($sql)){
    echo "<script language='javascript'>"; 
                    echo " location='index.php';"; 
                    echo "</script>";
    }else echo "提交失败,请重启提交!";
    }
    ?>
    <form action="" method="post">
    <table>              <thead>  
                    <tr>
    <td>
    <input  onclick="addMyRow();" type="button" name="call" value="添加"/>
    </td>
    </tr>
                   <tr>  
       <td  style="display:none" bgcolor="#CCCCCC" scope="col" align="center">  
                            编号  
                       </td>  
                        <td bgcolor="#CCCCCC" scope="col" align="center">  
                            姓名   
                       </td>  
                       <td bgcolor="#CCCCCC" scope="col" align="center">  
                            主叫   
                        </td>  
                        <td bgcolor="#CCCCCC" scope="col" align="center">  
                            被叫   
                        </td>   
                        <td bgcolor="#CCCCCC" scope="col" align="center">  
                            操作   
                        </td>  
                    </tr>  
                </thead>  
                <tbody id="mybody"> 
    <?php
    //这里是PHP代码
    foreach ($result as $k=>$v) //循环开始
    {
    ?> 
    <tr>
    <td style="display:none"><input type="text" name="id" id="id" value="<?php echo $v['id']; ?>"/></td>
    <td><input type="text" name="call_name" id="call_name" value="<?php echo $v['call_name']; ?>"/></td>
                  <td><input type="text" name="first_callee" id="first_callee" value="<?php echo $v['first_callee']; ?>" /></td>
                  <td><input type="text" name="sec_callee" id="sec_callee" value="<?php echo $v['sec_callee']; ?>" /></td>
                    <td><input name="modify" type="submit" id="modify" value="更新" />
    <input name="del" type="submit" id="del" value="删除" />
     </td>
             </tr>
    <?php
    }
    ?>
                </tbody>  

            </table>  
    </form></div>
    </div>
    但是添加还是错误