-4

i am getting an error

Notice: Undefined index: name in C:\wamp\www\var\filter\filter.php

This my code

<?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>';


}

?>

can anyone tell me why i am getting this error .thanks

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;
    });
    });
Xavi
  • 2,552
  • 7
  • 40
  • 59

1 Answers1

0

Use ISSET .

try this

  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";
  }

EDIT:

change this

    data: dataString,

to

    data: {
    name: name
            },
echo_Me
  • 37,078
  • 5
  • 58
  • 78