使用PHP Mysql添加HTML按钮

使用PHP Mysql添加HTML按钮,php,mysql,Php,Mysql,在我正在构建的应用程序中,我需要为具有不同名称(HOD、主管或员工)的用户显示不同类型的按钮。 考虑代码片段-< /p> <button id="request">Leave Request</button> <button id="statistics">Leave Statistics</button> <?php $sql = "SELECT Role from emplo

在我正在构建的应用程序中,我需要为具有不同名称(HOD、主管或员工)的用户显示不同类型的按钮。 考虑代码片段-< /p>
        <button id="request">Leave Request</button>
        <button id="statistics">Leave Statistics</button>
        <?php
        $sql = "SELECT Role from employee where `Emp Code`=$emp_code";
        $result = mysqli_query($link,$sql);
        $row =mysqli_fetch_array($result, MYSQLI_NUM);
        if($row[0] == "HOD"){
            echo "<button id='new'> New Button</button>";
        }
请假请求
休假统计
请试试这个

        <button id="request">Leave Request</button>
        <button id="statistics">Leave Statistics</button>
        <?php
        $sql = "SELECT `role` from employee where `emp_code`='".$emp_code."'";
        $result = mysqli_query($sql);
        $row =mysqli_fetch_array($result, MYSQLI_NUM);
        if($row[0] == "HOD"){
            echo "<button id='new'> New Button</button>";
        }
请假请求
休假统计

我正在使用手机,但由于emp_代码是字符串,请尝试以下操作。请注意$emp_代码周围的“”

        <button id="request">Leave Request</button>
    <button id="statistics">Leave Statistics</button>
    <?php
    $sql = "SELECT Role from employee where `Emp Code`='$emp_code'";
    $result = mysqli_query($link,$sql);
    $row =mysqli_fetch_array($result, MYSQLI_NUM);
    if($row[0] == "HOD"){
        echo "<button id='new'> New Button</button>";
    }
请假请求
休假统计

正如注释中提到的OP,表结构是
emp\u名称、emp\u代码、密码、emailID、角色-varchar(50)
$emp\u代码是字符串

并且查询操作正在尝试

$sql = "SELECT Role from employee where `Emp Code`=$emp_code";
所以查询应该是

$sql = "SELECT role FROM employee WHERE emp_code='$emp_code'";

您的查询失败,您需要找出为什么是查询($link,$sql)还是死亡(mysqli_错误($link))
$row=mysqli\u fetch\u数组($result,mysqli\u NUM)employee
table structure.emp_名称、emp_代码、密码、emailID、角色-varchar(50)请查看更新的答案。。使用emp_代码而不是emp代码。根据您的表结构修改$sql查询$sql=“从员工中选择
emp_代码
=$emp_代码”;即使我使用“从员工中选择角色,其中
Emp code
='aal01'”。aal01是“Emp Code”列中的一个值,它显示相同的错误检查答案中的查询,查询中的表列名称错误,如果如您在评论中所述,表col是
emp_code
,但在查询中,您正在尝试使用
emp code
,col
role
也是如此,并且您正在尝试使用
role
,则列名不可能是
emp code
不能在两个单词之间留出空格,所以完全是wrong@Fred-ii-是的,我同意你的意见
-
连字符也不练习。col name中两个单词之间的空格对我来说是新事物,很高兴我学到了一些东西。