用DW5编辑网页搜索页面时,预览中出现如下代码:
Notice: Undefined index: textfield in P:\leyou\search.php on line 224具体页面截图如下:具体代码如下(附代码截图):
<?php require_once('Connections/gongsi.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}$maxRows_Rs_search = 10;
$pageNum_Rs_search = 0;
if (isset($_GET['pageNum_Rs_search'])) {
  $pageNum_Rs_search = $_GET['pageNum_Rs_search'];
}
$startRow_Rs_search = $pageNum_Rs_search * $maxRows_Rs_search;$colname_Rs_search = "-1";
if (isset($_POST['textfield'])) {
  $colname_Rs_search = $_POST['textfield'];
}
mysql_select_db($database_gongsi, $gongsi);
$query_Rs_search = sprintf("SELECT * FROM xinwen WHERE biaoti LIKE %s", GetSQLValueString("%" . $colname_Rs_search . "%", "text"));
$query_limit_Rs_search = sprintf("%s LIMIT %d, %d", $query_Rs_search, $startRow_Rs_search, $maxRows_Rs_search);
$Rs_search = mysql_query($query_limit_Rs_search, $gongsi) or die(mysql_error());
$row_Rs_search = mysql_fetch_assoc($Rs_search);if (isset($_GET['totalRows_Rs_search'])) {
  $totalRows_Rs_search = $_GET['totalRows_Rs_search'];
} else {
  $all_Rs_search = mysql_query($query_Rs_search);
  $totalRows_Rs_search = mysql_num_rows($all_Rs_search);
}
$totalPages_Rs_search = ceil($totalRows_Rs_search/$maxRows_Rs_search)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/muban.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>搜索页</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
body,td,th {
font-family: "宋体";
font-size: 14px;
color: #333;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a {
font-family: "宋体";
font-size: 14px;
color: #333;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #333;
}
a:hover {
text-decoration: none;
color: #F00;
}
a:active {
text-decoration: none;
color: #F00;
}
.Daohang {
font-family: "宋体";
font-size: 16px;
font-style: normal;
font-weight: bold;
color: #FFF;
text-decoration: none;
}
.Biaoti {
font-family: "宋体";
font-size: 14px;
font-weight: bold;
color: #F00;
}
.BiaotiK {
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: none;
border-right-style: none;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #CCC;
border-right-color: #CCC;
border-bottom-color: #CCC;
border-left-color: #CCC;
}
.UxingK {
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: none;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #CCC;
border-right-color: #CCC;
border-bottom-color: #CCC;
border-left-color: #CCC;
}
.SsbeijingK {
background-image: url(../images/sskuang.png);
}
.SswenbenK {
border:0px none #FFF;
height:30px;
width:340px;
font-size:24px;
outline:none;
}
Daohang a:link {
font-family: "宋体";
font-size: 16px;
font-weight: bold;
color: #FFF;
text-decoration: none;
}
Daohang a:visited {
font-family: "宋体";
font-size: 16px;
color: #FFF;
text-decoration: none;
}
</style>
</head><body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="32" class="BiaotiK"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="BiaotiK">
      <tr>
        <td width="111" height="25">欢迎访问本网站</td>
        <td width="98" height="25">
        <?php
     if(!isset($_SESSION)){session_start();}
 if(isset($_SESSION["zhanghao"])){echo $_SESSION['zhanghao'];}
    ?>
        </td>
        <td width="90" height="25">&nbsp;</td>
        <td width="90" height="25">&nbsp;</td>
        <td width="90" height="25">&nbsp;</td>
        <td width="90" height="25">&nbsp;</td>
        <td width="90" height="25">&nbsp;</td>
        <td width="90" height="25">&nbsp;</td>
        <td width="98" height="25">注册</td>
        <td width="98" height="25">登入</td>
      </tr>
    </table>
      <table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="326"><img src="logo/logo.png" alt="" width="326" height="129" /></td>
          <td><form id="form1" name="form1" method="post" action="search.php">
            <table width="470" border="0" align="center" cellpadding="0" cellspacing="0" class="SsbeijingK">
              <tr>
                <td width="370" height="45" align="right"><label for="search"></label>
                  <input name="search"  value="<?php if(isset($_POST['textfield'])){echo $_POST['textfield'];} ?>" type="text" class="SswenbenK" id="search"  width="370" height="45" /></td>
                <td width="100" height="45"><input type="image" name="imageField" id="imageField" src="images/ssniu.png" /></td>
              </tr>
            </table>
          </form></td>
        </tr>
      </table>
      <table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="Daohang">
        <tr>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">网站首页</td>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">乐游动态</td>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">景区景点</td>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">旅游特产</td>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">旅游服务</td>
          <td height="40" align="center" bgcolor="#4d5b66" class="Daohang">乐游路线</td>
        </tr>
      </table>
      <table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><img src="logo/banner.gif" width="980" height="200" /></td>
        </tr>
      </table>
      <table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><!-- InstanceBeginEditable name="EditRegion3" -->
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>搜索有关<?php echo $_POST['textfield']; ?>的内容是:
                  <?php if ($totalRows_Rs_search == 0) { // Show if recordset empty ?>
                    这里没有你要搜索的内容!
  <?php } // Show if recordset empty ?></td>
              </tr>
              <tr>
                <td><a href="nr.php?id=<?php echo $row_Rs_search['id']; ?>">
                  <?php do { ?>
                    <?php echo $row_Rs_search['biaoti']; ?>
                    <?php } while ($row_Rs_search = mysql_fetch_assoc($Rs_search)); ?>
                </a></td>
              </tr>
            </table>
          <!-- InstanceEndEditable --></td>
        </tr>
      </table>
      <br />
      <table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="100" align="center" valign="middle" bgcolor="#eeeeee"><p>乐游侨乡:乐游游乐悠悠!</p>
            <hr width="98%" style="color:#f15a24; height:1px" />
          <p>copyright&copy;:乐游侨乡  &nbsp;版权所有!</p></td>
        </tr>
      </table>
<p>&nbsp;</p></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Rs_search);
?>

解决方案 »

  1.   

    你的表单中只有 <input name="search"  ,并未名为 textfield 的控件,自然 $_POST['textfield'] 是不存在的
      

  2.   

    textfield 没有初始化
      

  3.   


    要怎么做?小白不懂
    <input name="search"  value="<?php if(isset($_POST['textfield'])){echo $_POST['textfield'];} ?>" type="text" class="SswenbenK" id="search"  width="370" height="45" />
    $_POST['value'] 这个‘value’ 得是<input name="search" .../>里的name属性的值,
    要么把 $_POST['textfield'] 改成 $_POST['search'],
    要么把input标签的 name="search" 改成 name="textfield"