注意:未定义的索引:c: wamp www mit search.php在第7行中的SR



我是PHP的初学者,所以我不知道问题是什么和是什么问题。当我执行代码

注意:未定义的索引:c: wamp www www mit search.php在第7行7

显示,但是,搜索操作正在工作。

search.php

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("display") or die ("could not find db"); 
 $output ='';
 if (isset ($_POST['sr']));
$search = $_POST['sr'];
$query = mysql_query("SELECT * FROM photos WHERE firstname LIKE '%$search%'" 
)   or die("could not search");
$count = mysql_num_rows($query);
if($count == 0)
{
    $output = 'There was no search results !';
    }
    else
    {
    while($row = mysql_fetch_array($query))
    {
    $fname = $row['firstname'];
    $lastname = $row['lastname'];
    $fathername = $row['fathername'];
    $mothername = $row['mothername'];
    $sex = $row['sex'];
    $dob = $row['dob'];
    $religion = $row['religion'];
    $email = $row['email'];
    $password = $row['password'];   
    $cell = $row['cell'];   
    $tphone = $row['tphone'];   
    $address = $row['address'];
    $town = $row['town'];   
    $city=$row['city'];
    $state=$row['state'];
    $country=$row['country'];
    $pin=$row['pin'];
    $nationality=$row['nationality'];
    $eq1=$row['eq1'];
    $eq2=$row['eq2'];
    $eq3=$row['eq3'];
    $eq4=$row['eq4'];
    $location=$row['location'];
    //$output .='<div> '.$fname.''.$lastname.'</div>';
    $output .='<table border="1px"><tr><td>'.$fname.'</td>
 <td>'.$lastname.'</td>'.$fathername.'</td><td>'.$mothername.'</td>
<td>'.$sex.'</td><td>'.$dob.'</td><td>'.$religion.'</td><td>'.$email.'</td>
<td>'.$password.'</td><td>'.$cell.'</td><td>'.$tphone.'</td>
<td>'.$address.'</td><td>'.$town.'</td><td>'.$city.'</td><td>'.$state.'</td>
<td>'.$country.'</td><td>'.$pin.'</td><td>'.$nationality.'</td>
<td>'.$eq1.'</td><td>'.$eq2.'</td><td>'.$eq3.'</td><td>'.$eq4.'</td><td><img 
width="100px" height="100px" src="'.$location.'">'.'</td></tr></table>';
    }
    }
?>
<html>
<head>
<title>search</title>
</head>
 <body>
<form action="search.php" method="post">
<input type="text" name="sr" placeholder="search for members"/> 
<input type="submit" value="Search"/>
</form>
<?php echo $output;?>
</body>
</html> 

修改(如果之后您有分号(

if (isset ($_POST['sr']));

to

if (isset($_POST['sr'])){
           // Your other statement goes here
}

否则

if (!isset ($_POST['sr'])){
       die( "Search keyword not found" );
}

在第6行上的if (isset ($_POST['sr']));之后删除;

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("display") or die ("could not find db"); 
$output ='';
if (isset ($_POST['sr']))
    $search = $_POST['sr'];
$query = mysql_query("SELECT * FROM photos WHERE firstname LIKE '%$search%'" 
    )   or die("could not search");
$count = mysql_num_rows($query);
if($count == 0)
{
    $output = 'There was no search results !';
}
else
{
    while($row = mysql_fetch_array($query))
    {
        $fname = $row['firstname'];
        $lastname = $row['lastname'];
        $fathername = $row['fathername'];
        $mothername = $row['mothername'];
        $sex = $row['sex'];
        $dob = $row['dob'];
        $religion = $row['religion'];
        $email = $row['email'];
        $password = $row['password'];   
        $cell = $row['cell'];   
        $tphone = $row['tphone'];   
        $address = $row['address'];
        $town = $row['town'];   
        $city=$row['city'];
        $state=$row['state'];
        $country=$row['country'];
        $pin=$row['pin'];
        $nationality=$row['nationality'];
        $eq1=$row['eq1'];
        $eq2=$row['eq2'];
        $eq3=$row['eq3'];
        $eq4=$row['eq4'];
        $location=$row['location'];
    //$output .='<div> '.$fname.''.$lastname.'</div>';
        $output .='<table border="1px"><tr><td>'.$fname.'</td>
        <td>'.$lastname.'</td>'.$fathername.'</td><td>'.$mothername.'</td>
        <td>'.$sex.'</td><td>'.$dob.'</td><td>'.$religion.'</td><td>'.$email.'</td>
        <td>'.$password.'</td><td>'.$cell.'</td><td>'.$tphone.'</td>
        <td>'.$address.'</td><td>'.$town.'</td><td>'.$city.'</td><td>'.$state.'</td>
        <td>'.$country.'</td><td>'.$pin.'</td><td>'.$nationality.'</td>
        <td>'.$eq1.'</td><td>'.$eq2.'</td><td>'.$eq3.'</td><td>'.$eq4.'</td><td><img 
        width="100px" height="100px" src="'.$location.'">'.'</td></tr></table>';
    }
}
?>
<html>
<head>
    <title>search</title>
</head>
<body>
    <form action="search.php" method="post">
        <input type="text" name="sr" placeholder="search for members"/> 
        <input type="submit" value="Search"/>
    </form>
    <?php echo $output;?>
</body>
</html> 

删除;在第6行

中进行之后

相关内容

最新更新