删除数据后出错,注意:未定义的索引:搜索

时间:2013-11-05 09:28:19

标签: php

好吧,这是我的错误,数据已成功删除,但错误出来了.. 这是我的search.php编码。第30行的错误

<?
mysql_connect("localhost","root","");
mysql_select_db("kuih2") or die("database could not connect ");
?>

search.php的html代码

<html>
    <head>
    <meta name="description" content="Php Code for View, Search, Edit and Delete
    Record" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Search Student Record</title>
    </head>
    <body>
    <center><h1><u>Student Database</u></h1></center>
    <form name="search" method="post" action="search.php">
    <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px"
    align="center" border="0">
    <tr>
    <td colspan="3" style="background:#0066FF; color:#FFFFFF; fontsize:
    20px">Search</td></tr>
    <tr>
    <td>Enter Search Keyword</td>
    <td><input type="text" name="search" size="40" /></td>
    <td><input type="submit" value="Search" /></td>
    </tr>
    <tr bgcolor="#666666" style="color:#FFFFFF">
    <td>Roll & class</td>
    <td>Name & Father's Name</td>
    <td>&nbsp;</td>

search.php编码

<?
    $search=$_POST["search"];//the error is here
    $flag=0;
    $query="select * from itemorder where id like '%$search%' ";
    $result=mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        $flag=1;
    echo "<tr ><td>",$row[0],", ",$row[1],"</td><td><a
    href='view.php?id=",$row[0],"'>",$row[2],", ",$row[3],"</a></td><td><a
    href='edit.php?id=",$row[0],"'>Edit</a> | <a
    href='del.php?id=",$row[0],"'>Delete</a></td></tr>";
    }
    if($flag==0)
    echo "<tr><td colspan='3' align='center' style='color:red'>Record not
    found</td></tr>";
    ?>
    <tr>
    <td colspan="3">&nbsp;</td></tr>
    <tr bgcolor="#CCCCCC">
    <th colspan="3" align="right"></th>
    </tr>
    </table>
    </form>
    </body>
    </html>

那么这是我的del.php编码......

<?
    mysql_connect("localhost","root","");
    mysql_select_db("kuih2") or die("database could not connect ");
    ?>
    <html>
    <head>
    <meta name="description" content="Php Code for View, Search, Edit and Delete
    Record" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Add Student Record</title>
    </head>
    <body>
    <?
    $id=$_GET["id"];
    $query="delete from itemorder where id=$id";
    mysql_query($query);
    echo "<center>Successfully Deleted</center>";
    include("search.php");
    ?>

2 个答案:

答案 0 :(得分:0)

这是因为删除后你包含了这样的文件

 <?
    $id=$_GET["id"];
    $query="delete from itemorder where id=$id";
    mysql_query($query);
    echo "<center>Successfully Deleted</center>";
    //include("search.php"); // I have commented this line
    ?>

search.php文件需要 POST 参数,您发送 not 。因此错误。

解决方案:最后评论 include

答案 1 :(得分:0)

试试这个:

if(isset($_POST["search"])){
$search=$_POST["search"];
}