没有以PHP搜索形式显示的记录

时间:2017-11-29 06:32:33

标签: php

任何人都可以告诉我为什么这段代码不会给我任何记录并显示我的“其他”错误信息呢?我试图从(附加)获取数据的表使用来自两个其他表格的两个忘记密钥(emp编号和项目代码) (请注意我是PHP新手)enter image description here

$emp_no="";
$project_code="";
$p_hours="";

require_once 'connect.php';


function getposts()
{
$posts= array();
if (isset($_POST['EMPNo']))
{
$posts[0] = $_POST['EMPNo']; 
}
if (isset($_POST['ProjectCode']))
{
$posts[1] = $_POST['ProjectCode'];
}
if (isset($_POST['Hours']))
{
$posts[2] = $_POST['Hours'];
 }
 return $posts; 

 }


  if(isset($_POST['search']))
  {
   @$data = getposts();
  @$searchquery = "SELECT * FROM  `enrolment` WHERE `EMPNo`='$data[0]' AND 
  `ProjectCode`='$data[1]'";
  @$search_Result =mysqli_query($connect, $searchquery);
   if($search_Result)
  { 
  if(mysqli_num_rows($search_Result))
   {
     while($raw = mysqli_fetch_array($search_Result))
     {
        $emp_no = $raw ['EMPNo'] ;
        $project_code = $raw ['ProjectCode'] ;
        $p_hours = $raw ['Hours'] ;
     }           
   }else {
       echo 'Unable to find the record please check input data!';
   }

     }else {
     echo ' Result Error ';
     }

   }

//html part
  <Form action="updateenrolment.php" method="post" style="color:blue;margin-
  left:500px;"> 
  <input type="text" name ="empno" placeholder="Employee No" value="<?php 
  echo $emp_no;?>"><br><br>
  <input type="text" name ="pcode" placeholder="Project Code" value="<?php 
  echo $project_code;?>"><br><br> 
  <input type="number" name ="hours" placeholder="Hours" value="<?php echo 
  $p_hours;?>"><br><br>
  <div> 
     <input type="submit" name ="search" value="Find" >

1 个答案:

答案 0 :(得分:0)

mysqli_fetch_array打印数组结果,但是您使用字符串元素获取结果。你需要改变它。

 while($raw = mysqli_fetch_array($search_Result))
 {
    $emp_no = $raw [1] ;
    $project_code = $raw [2] ;
    $p_hours = $raw [3] ;
 }

替换它。

while($raw = mysqli_fetch_array($search_Result))
 {
    $emp_no = $raw ['EMPNo'] ;
    $project_code = $raw ['ProjectCode'] ;
    $p_hours = $raw ['Hours'] ;
 }