我的数据库数据没有显示

时间:2017-03-04 10:57:38

标签: php mysql pdo

我是一个使用pdo的新手,我对此并不熟悉。我试图使用会话将数据添加到我的数据库,但是当我做了它从数据库中检索数据时出错了。 我希望你能帮助我。这是为了我的毕业。谢谢

  

她是我用于显示数据库数据的代码..

<?php
// include database connection

 include 'crud_database.php';



 $query = "SELECT * FROM tbl_profile  ORDER BY dept ASC";
 $stmt = $con->prepare($query);
 $stmt->execute();
 $test=$stmt->fetch();
 $_SESSION['profile'] = $test;



 $num = $stmt->rowCount();


 if($num>0){
 echo "<table class='table table-hover table-responsive table-bordered' id='mydata'>";//start table

    // head
    echo "<thead>";
    echo "<tr>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Department</th>";
    echo "<th>ACTION</th>";
    echo "</tr>";
    echo "</thead>";

    // foot
    echo "<tfoot>";
    echo "<tr>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Department</th>";
    echo "<th>ACTION</th>";
    echo "</tr>";
    echo "</tfoot>";


    // retrieve our table contents
    // fetch() is faster than fetchAll()
    // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['firstname'] to
        // just $firstname only
        extract($row);

        // creating new table row per record
        echo "<tr>";
        echo "<td>{$fname}</td>";
        echo "<th>{$lname}</th>";
        echo "<th>{$dept}</th>";

        echo "<td align='center'>";

        // read one record 
        echo "<a href='superadmin_view_more_training.php?empid={$empid}' class=' fa fa-eye' title='View'></a>";
        echo "</tr>";
    }

// end table
echo "</table>";

}

// if no records found
else{
echo "<div align=center>No records found.</div>";
}

?>
  

这是我添加数据的代码..

<?php
session_start();
require_once('database_action.php');
$storage = new storage();

$test = $_SESSION['profile'];
if(isset($_POST['btn-save']))
{
$empid = $test['empid'];
$empname = $test['fname'];
$seminar = strip_tags($_POST['seminar']);
$sdate = $_POST['sdate'];
$edate = $_POST['edate'];
$hour = strip_tags($_POST['hour']);
$conduct = strip_tags($_POST['conduct']);

if($storage->savetraining($empid,$empname,$seminar,$hour,$conduct,$sdate,$edate))
{  
  $storage->redirect('superadmin_view_training.php?joined');
}

}
?>

0 个答案:

没有答案