我收到错误
Notice: Undefined index: name in C:\wamp\www\var\filter\filter.php
这是我的代码
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'root';
$dbPassword = 'xxxxxx';
$dbDatabase = 'filter';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$name = $_POST['name'];
$sql_selectsupplier = "SELECT * FROM contact";
print $sql_selectsupplier;
$result1 = mysql_query($sql_selectsupplier);
if ($name !=""){
$sql_selectsupplier.=" AND name = '".$name."'";
}
while($rows=mysql_fetch_assoc($result1))
{
echo '<tr>';
echo '
<td class="edit name '.$rows["id"].'" >'.$rows["name"].'</td>
</tr>';
}
?>
任何人都可以告诉我为什么我会收到此错误。谢谢
AJAX:
$(function() {
$(".filtercontact").click(function() {
var name = $("#name").val();
var dataString = 'name='+ name ;
if(name=='')
{
alert("Please Enter Some Text");
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html;
$.ajax({
type: "POST",
url: "filter.php",
data: dataString,
cache: false,
success: function(result){
window.location = 'http://localhost/var/filter/filter.php';
$("#flash").hide();
}
});
} return false;
});
});
答案 0 :(得分:0)
使用ISSET。
试试这个
if(isset($_POST['name'])){
$name = $_POST['name'];
$sql_selectsupplier = "SELECT * FROM contact";
print $sql_selectsupplier;
$result1 = mysql_query($sql_selectsupplier);
if ($name !=""){
$sql_selectsupplier.=" AND name = '".$name."'";
}
while($rows=mysql_fetch_assoc($result1)){
echo '<tr>';
echo '<td class="edit name '.$rows["id"].'" >'.$rows["name"].'</td></tr>';
}
} else {
echo "name is not set";
}
编辑:
更改此
data: dataString,
到
data: {
name: name
},