如何解决PHP中的未定义索引错误

时间:2019-06-26 04:32:44

标签: php

我正在使用php创建一个电子商务网站,同时打开搜索页面以显示正在显示错误的客户详细信息。

错误是 注意:未定义索引:第26行的F:\ Pro \ Alam \ ser.php中的searchusername

如果我搜索任何客户,则错误不会显示。仅在我打开搜索页面时第一次显示错误。请任何人帮助我解决此问题。我尝试了之前所说的大多数答案,但没有任何帮助。

我的代码是:

    <?php
session_start();

if($_SESSION['logged_in'] == 1)
    {
        $userfirstname = "";
        $usergender = "";
        $userheight = "";
        $userphone1 = "";
        $searchusername = "";

        include("config.php");

        $match = "SELECT * FROM $table WHERE username =  '".$_POST['searchusername']."'";

        $qry = mysql_query($match);

        while($userdetails = mysql_fetch_assoc($qry))
            {
                $userfirstname = $userdetails['firstname'];

                $usergender = $userdetails['gender'];

                $userheight = $userdetails['height'];

                $userphone1 = $userdetails['phone1'];
            }
    }
else
    {
        session_destroy();
        header("location:index.html");
    }

 ?>

 <html>

<body>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  name="searchbyno"   id="searchbyno" method = POST   enctype="multipart/form-data">

        <center>    <B>Username</b>

            <input type="text"  name="searchusername"   id="searchusername" >
            <input type="submit"    name="searchbtn"    id="searchbtn"  value="search">
        </center>
    </form>
</body>

0 个答案:

没有答案