doujingdai5521 2018-11-25 07:56
浏览 70

无法在PHP / HTML中生成SQL查询

I'm having some trouble generating output from an sql query via php. When I execute the query "SELECT * from projectdb WHERE name = 'Crys' or ID = 14142" on phpmyadmin it returns valid results, but attempting to do so by passing a post value yields an empty table. See code below:

<html>
<title>Search result</title>

<body>
<table border="1px">
    <tr>
    <td>name</td>
    <td>ID</td>
    <td>position</td>
    <td>job scope</td>
    <td>contact_no</td>
    <td>days_off</td>
    <td>wages</td>
    </tr>


<?php
if (isset($_POST['value']))
{
    $ID=$_POST['staff ID'];
    $name=$_POST['staff name'];


    $admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
    $sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
    while($result=mysqli_fetch_assoc($sqlsrch2)){

    ?>
/* table where results needs to be printed */
    <tr>
    <td><?php echo $result['name'];?></td>
    <td><?php echo $result['ID'];?></td>
    <td><?php echo $result['position'];?></td>
    <td><?php echo $result['job_scope'];?></td>
    <td><?php echo $result['contact_no'];?></td>
    <td><?php echo $result['days_off'];?></td>
    <td><?php echo $result['wages'];?></td>
    </tr>
    <?php
    }
}
    ?>
</table>
</body>
</html>

A few points to note:

  1. I'm just a beginner in PHP and SQL; I'm just looking for a simple answer.
  2. Security is not at all a concern here; this is just a rough demo. If this is marked as duplicate, do help redirect me to a link where I can get the solution. Thanks!
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型