本帖最后由 gg1082963 于 2010-07-26 13:06:44 编辑

解决方案 »

  1.   

    你get和post没分清
    混杂在一起 连你自己都不知道get执行啥 post访问时执行啥吧标题为啥要突出你是mm?你有贴照片的打算吗
      

  2.   


    <?php  
      if($_POST["submit2"]=="查询")
      {
       $txt_book=$_POST["text_book"];
    $sql = mysql_query("select * from tb_student2 where bookname '%".trim($txt_book)."%'",$connID);
    $info = mysql_fetch_object($sql);   echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
    while($info= mysql_fetch_object($sql))
    {  
    echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
    }
      }//if end
      ?>
      

  3.   

    Undefined index: submit2 in D:\wamp\www\xishuophp\k1.php on line 24??
    这这么错误?猪头920
      

  4.   

    因为你第一次运行的时候$_POST["submit2"]还没有被设置,要等到点submit2这个按钮时$_POST["submit2"]才有值。
    这只是一个Warning信息,可以通过设置error_reporting(E_ALL ^ E_NOTICE);来屏蔽这个信息,但是如果想代码严谨的话,可以使用下面的方法isset判断:
    <?php
    $host="127.0.0.1";
    $userName="root";
    $password="";
    $dbName="test01";
    $connID=mysql_connect($host,$userName,$password);
    mysql_select_db($dbName,$connID);
    mysql_query("set names gbk");
    ?>
    <form name="form1" action="$_SERVER['PHP_SELF']" method="post">
    <p>
    <label>请输入图书的名称</label>
    <input type="text" size="20" name="text_book">
    <input type="submit" name="submit2" value="查询">
    </p>
    </form>
    <?php
    if(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){
    $txt_book=$_POST["text_book"];
    $sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID);
    $info = mysql_fetch_object($sql);}
    echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
    while($info= mysql_fetch_object($sql)){
    echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
    }
    ?>
      

  5.   

    if(isset($_POST["submit2"]) && $_POST["submit2"]=="查询")
      

  6.   


    <?php
    if(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){
        $txt_book=$_POST["text_book"];
        $sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID);
        $info = mysql_fetch_object($sql);//这里是多余的}
    echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
    while($info= mysql_fetch_object($sql)){
        echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
    }
    ?>
      

  7.   

    if也不对噢 不把后面的包括进来 sql变量也会报错的  
    lz貌似修改了帖子
      

  8.   

    另外,说自己MM的,要带ID贴一张照片才能算数!