0

我正在尝试在一组选项卡旁边制作一个简单的搜索框,该搜索框仅用于搜索电话类型,我制作了此代码,除了搜索框之外的所有东西都可以工作。它给了我这个错误:注意:未定义的索引:搜索

<form action="" method="post" name="form" > 
<body>  
<script>
$(function() {
$( "#xx" ).tabs();
});
</script>


<div id="xx" >
<ul>
<li><a href="#all">all phones</a></li>
<li><a href="#small">small</a></li>
<li><a href="#large">large</a></li>
<li><a href="#search">search:<input type="text" name="search">
</a></li>
</ul>   

<?php
include 'db.php'; 
?>

<div id="all">
<?php 
$res = mysql_query("SELECT * FROM table1");
while($row = mysql_fetch_array($res))
{         
echo 'phone name'.$row[2];
echo 'phone type'.$row[3];
echo 'phone sise'.$row[4];
}
?> 
</div>


<div id="small">   
<?php 
$res2 = mysql_query("SELECT * FROM table1 WHERE phonesize = 'small' ");
while($row = mysql_fetch_array($res2))
{         
echo 'phone name'.$row[2];
echo 'phone type'.$row[3];
echo 'phone sise'.$row[4];
}
?> 
</div>

<div id="large">   
<?php 
$res3 = mysql_query("SELECT * FROM table1 WHERE phonesize = 'large' ");
while($row = mysql_fetch_array($res3))
{         
echo 'phone name'.$row[2];
echo 'phone type'.$row[3];
echo 'phone sise'.$row[4];
}
?> 
</div>


<div id="large">   

 <?php     
$search = $_POST['search'];   
$res4 = mysql_query("SELECT * FROM table1 WHERE phonetype = '$search'");
while($row = mysql_fetch_array($res4))
{         
echo 'phone name'.$row[2];
echo 'phone type'.$row[3];
echo 'phone sise'.$row[4];
}
?> 
</div> 


</form>
4

2 回答 2

1

第一次加载表单时,$_POST['search'] 不存在,这就是导致通知的原因。直到您实际发布到该变量存在的表单。在执行用户提交表单后要执行的代码之前,您应该检查该变量是否存在,例如:

if( isset( $_POST )) {
    // The form was posted.
    // Write your code here to execute once the user posts the form.
]
于 2013-08-03T07:21:31.323 回答
0

好............第一次加载表单时, $_POST['search'] 不存在,这就是导致通知的原因。直到您实际发布到该变量存在的表单。在执行用户提交表单后要执行的代码之前,您应该检查该变量是否存在,例如:

于 2013-12-23T12:46:15.307 回答