how to fix fatal error - Class 'User' not found in php - php

This is user class.
<?php
class User {
/*
*public static function get_all_users()
*/
public function get_all_users() {
global $link;
$result_set = $link->query("SELECT * FROM `user`");
return $result_set;
}
}
Above class is user class i made object but cannot access. Display all use page of html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Admin Panel ::: </title>
</head>
<body>
<h3>Users :</h3>
<table border="1">
<tr>
<th>S.N</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Password</th>
<th>E-mail</th>
<th>Contact</th>
<th colspan="2">Option</th>
</tr>
<?php
$user = new User();
$result_set = $user->get_all_users();
/*
*$result_set = User :: get_all_users(); - accessing user class using static keyword.
*/
$i = 1;
while ($row = mysqli_fetch_assoc($result_set)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['Contact']; ?></td>
<td>Update</td>
<td>Delete</td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
I can not access user class when I create object of user class and user class is inside includes folder and below HTML file is inside admin folder or admin ->viewuser.php and admin->includes->user.php it gives error.

You need to include that User class inside the viewuser.php script !
include_once("includes/user.php");
I am not sure organizing your folders like that is the best way to do but it should work.

Related

Display more information on an item php codeigniter

I have a database table in mysql that has 11 entities. When the user first searches for an item, my code displays 5 entities and then there is an link for the user to click to view more information on the item. When the user click the link it should lead them to a new page with information about the item that is clicked based on itemID. I don't know how to pass the itemID of the entity to the controller. Please help!
Here's my code:
Contoller:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class ItemView extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('itemModal');
}
public function index(){
$this->load->view('base');
$this->load->view('searchResult');
}
public function viewItems(){
//trying to get the id of the clicked item
$id = $this->input->post($rows['inventoryID']);
$data['results'] = $this->itemModal->get_items($id);
$this->load->view('base.php',$data);
$this->load->view('itemview.php',$data);
}
}
?>
Model:
<?php
class ItemModal extends CI_Model {
function __construct(){
parent::__construct();
}
function get_items($id){
$this->db->select('*');
$this->db->like('inventoryID',$id);
// Execute the query.
$query = $this->db->get('inventory');
// Return the results.
return $query->result_array();
}}?>
View:
<body>
<h1><center>Item List</center></h1>
<hr>
<div class="container">
<form method="post" action="<?php echo site_url('itemView/index'); ?>">
<table>
<tr>
<th><input type="radio" name="chk"></th>
<th>Inventory ID</th>
<th>Master Code</th>
<th>Item Name</th>
<th>Color Name</th>
<th>Location</th>
<th>Link to more information</th>
</tr>
<?php foreach($results as $rows):?>
<tr>
<td><input type="radio" name="chk"></td>
<td><?php echo $rows['inventoryID'] ?></td>
<td><?php echo $rows['masterCode'] ?></td>
<td><?php echo $rows['itemName'] ?></td>
<td><?php echo $rows['colorName'] ?></td>
<td><?php echo $rows['location'] ?></td>
<td>click to view more information</td>
</tr>
<?php endforeach; ?>
</table>
</form>
</div></body>
View for itemView
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/search.css">
<title>Item Information Page</title>
</head>
<body>
<h1><center>Item Information</center></h1>
<hr>
<div class="container">
</div>
<!-- End of Container -->
</body><br><br>
</html>
yo need to change like this
controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class ItemView extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper(array('url','form'));
$this->load->model('itemModal', 'model_items');
}
public function index(){
//get all items from db to display basic info in form
$data['items']=$this->model_items->get_all();
$this->load->view('base');
$this->load->view('searchResult', $data);
}
//get the specific item to be updated
public function updateItem( $id ){
$data['results'] = $this->model_items->get_item_by_id($id);
$this->load->view('base',$data);
//viw with inpus form to change the info and send to controller to be updated
$this->load->view('itemview',$data);
}
//get all items to be updated
public function updateItems(){
foreach($this->input->post() as $item => $value){
${$item} = $value;
}
//here you need to add logic to make wherever you want with all items selected in form
}
}
model itemModal
<?php
class ItemModal extends CI_Model {
function get_all(){
return $this->db->get('inventory')->result();
}
function get_item_by_id($id){
return $this->db->get_where('inventory', array('id' => $id))->row();
}
}
view searchResult
<form method="post" action="<?= site_url('itemView/updateItems'); ?>">
<table>
<tr>
<!-- select one or more items to be updated bach -->
<th><input type="checkbox" name="chk" value="<?= $rows->inventoryID ?>"></th>
<th>Inventory ID</th>
<th>Master Code</th>
<th>Item Name</th>
<th>Color Name</th>
<th>Location</th>
<th>Link to more information</th>
</tr>
<?php foreach($itemsas $rows):?>
<tr>
<td><input type="radio" name="chk"></td>
<td><?= $rows->inventoryID ?></td>
<td><?= $rows['masterCode'] ?></td>
<td><?= $rows['itemName'] ?></td>
<td><?= $rows['colorName'] ?></td>
<td><?= $rows['location'] ?></td>
<!-- update specific item -->
<td>click to view more information</td>
</tr>
<?php endforeach; ?>
<tr>
<td>Update all items selected</td>
<td><input type="submit" value="Update"></td>
</tr>
</table>
</form>

my records are not displaying

in my project i try to display data from database and this is my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="prac.css">
<title>PHP Practical</title>
</head>
<body>
<div class="main">
<table class="table">
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Contact</th>
<th>Employee Salary</th>
<th>Employee Phone</th>
<th>Employee City</th>
<th>Join Date</th>
<th>Action</th>
</tr>
<?php
require 'config.php';
$query = mysql_query("SELECT * FROM emp");
while ($row = mysql_fetch_array($query)) {
?>
<tr>
<td><?php echo $row['emp_id']; ?></td>
<td><?php echo $row['emp_name']; ?></td>
<td><?php echo $row['emp_contact']; ?></td>
<td><?php echo $row['emp_salary']; ?></td>
<td><?php echo $row['emp_phone']; ?></td>
<td><?php echo $row['emp_city']; ?></td>
<td><?php echo $row['join_date']; ?></td>
<td>Update | Delete</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
i checked my config.php file and it is working fine and in database i have 6 records but it is not displaying any. i try also run query to database and it is working fine in database but not here. please help me.
**Use this**
$query = mysql_query("SELECT * FROM emp") or die(mysql_error());
to display mysql error
The mysql_ extension is deprecated. There is no point in using it.
Switch to mysqli or PDO
The issue you are currently facing is not caused because of mysql_ being deprecated but there's no worth in investigating it. It's not used anymore

datatables pagination, search won't work

I just started using datatables and the instructions to initialize the table seems easy enough.
I am able to get the table to appear and all of the data is inside, however both the pagination and search function doesn't work.
Please help.
This is my code:
<?php
Include 'DBFunctions.php';
?>
<html>
<head>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="DataTables-1.10.9/media/css/jquery.dataTables.css">
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="DataTables-1.10.9/media/js/jquery.dataTables.js"></script>
</head>
<body>
<?php
$queryData = "select c.*, o.officer_name from coa c, officer o WHERE o.persnum = c.importing_officer ORDER BY date_imported DESC";
$resultData = mysqli_query($link, $queryData) or die(mysqli_error($link));
?>
<h1>View All COAs</h1><br>
<table id="myTable" class="display">
<thead>
<tr>
<th>PO Number: </th>
<th>Chemical Name: </th>
<th>COA Date: </th>
<th>Quantity: </th>
<th>Plant Name: </th>
<th>Parameter Results: </th>
<th>Importing Officer: </th>
<th>COA Attempt: </th>
<th>Date Imported: </th>
<th>Pass/Fail: </th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_array($resultData)) {
?>
<tbody>
<tr>
<td><?php echo $row['po_number']?></td>
<td><?php echo $row['chemical_name']?></td>
<td><?php echo $row['date_coa']?></td>
<td><?php echo $row['quantity']?></td>
<td><?php echo $row['plant_name']?></td>
<td><?php echo $row['parameters_results']?></td>
<td><?php echo $row['officer_name']?></td>
<td><?php echo $row['coa_attempt']?></td>
<td><?php echo $row['date_imported']?></td>
<td><?php echo $row['pass_or_fail']?></td>
</tr>
</tbody>
<?php } ?>
</table>
<script>
$(document).ready( function () {
$('#myTable').DataTable({
});
} );
</script>
</body>
</html>
Take <tbody> out of the while loop so it looks like:
<tbody>
<?php
while ($row = mysqli_fetch_array($resultData)) {
?>
<tr>
<td><?php echo $row['po_number']?></td>
<td><?php echo $row['chemical_name']?></td>
<td><?php echo $row['date_coa']?></td>
<td><?php echo $row['quantity']?></td>
<td><?php echo $row['plant_name']?></td>
<td><?php echo $row['parameters_results']?></td>
<td><?php echo $row['officer_name']?></td>
<td><?php echo $row['coa_attempt']?></td>
<td><?php echo $row['date_imported']?></td>
<td><?php echo $row['pass_or_fail']?></td>
</tr>
<?php } ?>
</tbody>
You will have to enable the various options that datatable provide, for search and pagination you need to do this.
You should check the documentation for other available options
$(document).ready( function () {
$('#myTable').DataTable({
"paging": true,
"searching": true,
});
} );

Error: 1Helper could not be found. - cakephp

I am trying to create a index method for the content model controller and I am getting the following error, I searched here but did not find the relevant answer. Please take a look at the following code and screenshot:
Content.php:
class Content extends AppModel{
public $name = 'Content';
}
ContentsController.php:
class ContentsController extends AppController {
public $name = 'Contents';
public function index() {
$this->set('Contents', $this->Content->find('all'));
}
}
index.ctp:
<h1>View All Content</h1>
<table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php foreach ($Contents as $content) : ?>
<tr>
<td><?php echo $this->$content['Content']['id']; ?></td>
<td><?php echo $this->$content['Content']['title']; ?></td>
<td><?php echo $this->$content['Content']['content']; ?></td>
</tr>
<?php endforeach; ?>
</table>
Screenshot:
http://postimg.org/image/sslcgoutx/
Please help as I am new to cakephp and learning it.
Try this in index.ctp
<h1>View All Content</h1> <table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php foreach ($Contents as $content) : ?>
<tr>
<td><?php echo $content['Content']['id']; ?></td>
<td><?php echo $content['Content']['title']; ?></td>
<td><?php echo $content['Content']['content']; ?></td>
</tr>
<?php endforeach; ?>
</table>

Trouble using tablesorter jquery plug in with php generated table

I'm asking a user to fill out a form and I want to display that information in table format. Then, I want the user to be able to sort the table from the header row on each column. I am trying to use the jquery tablesorter plug in but cannot seem to get it to work. Does the plug in not work with PHP generated tables?
<!DOCTYPE HTML>
<html>
<head>
<title>Dashboard</title>
<link href ="table.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
<script type = "text/javascript">
$(document).ready(function() {
$("#sortedtable").tablesorter();
});
</script>
</head>
<body>
<?php
unset($_SESSION['errors_record']);
define("WEB_DB", "server_db");
define("DB_USER", "root");
define("DB_PASS", "prog");
$db_host = "localhost";
MYSQL_CONNECT($db_host,DB_USER,DB_PASS);
mysql_select_db(WEB_DB);
?>
<p><h1>SRG TDE Technical Review Dashboard</h1></p>
<p>
<button>Create a New Review Record</button>
Logout
</p>
<div class="CSSTableGenerator">
<table id = "sortedtable" class = "tablesorter">
<thead>
<tr>
<th>Review Record ID</th>
<th>Project</th>
<th>Date</th>
<th>Author</th>
<th>Moderator</th>
<th>Portfolio Lead</th>
<th>Review Artifact Type</th>
<th>Review Artifact Name</th>
<th>Version</th>
</tr>
$sql = "select record_id,project,date,author,moderator,portlead,rtype,rname,version from dashboard_table ORDER BY date DESC";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if ($num)
{
while(list($record_id,$project,$date,$author,$moderator,$portlead,$rtype,$rname,$version) = mysql_fetch_row($result))
{
?>
<?php $url="http://localhost/main_tab.php?record=" . $record_id ?>
<tbody>
<tr>
<td><?php echo "<a href = '$url'>$record_id</a>";?></td>
<td><?php echo $project?></td>
<td><?php echo $date?></td>
<td><?php echo $author?></td>
<td><?php echo $moderator?></td>
<td><?php echo $portlead?></td>
<td><?php echo $rtype?></td>
<td><?php echo $rname?></td>
<td><?php echo $version?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</body>
</html>
I'm not that good with php, but it appears that the table being built will have every row wrapped in a new tbody. Move the initial <tbody> outside of the while loop:
if ($num)
{
echo "<tbody>";
while(list($record_id,$project,$date,$author,$moderator,$portlead,$rtype,$rname,$version) = mysql_fetch_row($result))
{
?>
<?php $url="http://localhost/main_tab.php?record=" . $record_id ?>
<tr>
<td><?php echo "<a href = '$url'>$record_id</a>";?></td>
<td><?php echo $project?></td>
<td><?php echo $date?></td>
<td><?php echo $author?></td>
<td><?php echo $moderator?></td>
<td><?php echo $portlead?></td>
<td><?php echo $rtype?></td>
<td><?php echo $rname?></td>
<td><?php echo $version?></td>
</tr>
<?php
}
}
?>
</tbody>

Categories