duanbaque4230 2015-03-02 03:59
浏览 21

使用函数从PHP MySQL数据库驱动的网站获取电子邮件地址的名称

I have a database driven website that has a login to a member or admin area. The login says, "Welcome, Member, pat@email.com" (for example) and I want it to say - "Welcome, Member, Pat" (for example). I have a function that I know works for this, but for some reason I can't get it to work now. It is giving me this error and saying that results is NULL:

Notice: Undefined variable: results in J:\XAMPP\htdocs\tire\admin\home.php on line 59

Below is the two different get_name functions I've tried - note that I have tried one of these and didn't have any trouble getting it to work before.

 function get_name($results) {
    $name = preg_split("/@/", $results['email']);
    $name = ucfirst($name[0]);
    return $name;
 }

function get_name($results) {
list($name, $email) = array_pad(explode('@', $results['name'], 2), 2, null);
  return $name;
 }

And here is the logout form:

<form action="index.php" method="post" id="logoutform.php">

                    <fieldset>
                        <legend>Logout</legend>

                        <?php
                    echo "Welcome, ";
                            echo $_SESSION['level']. ", ";
                            echo $_SESSION['loginName'];

                            echo get_name($results); 
                            var_dump($results);
                    ?>  <br /> <br/> <br/> <br/>
                        <input type="submit" name="action" value="logout"/>

                </fieldset>
                </form>

Connect function:

function connect($loginName) {
    global $db;
    $query = "SELECT email, level, password FROM members WHERE email    = '$loginName'";
    $result = $db->query($query);
    $results = $result->fetch(PDO::FETCH_ASSOC);
    return $results;
 }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大