Object of class __PHP_Incomplete_Class could not be converted to string - php

Hi I have this error "Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in C:\xampp\htdocs\ProjectTA\dao\CustomerDao.php on line 161" like this, I have no idea to solve this problem I check all and everything is fine to me
this my Customer dao
public function getOneCustomer($id) {
try {
$conn = Connection::getConnection();
$query = "select * from Customer c join Company comp on c.Company_IdCompany = comp.IdCompany JOIN City cit ON c.City_Id = cit.IdC WHERE c.IdCustomer = ?";
$stmt = $conn->prepare($query);
$stmt->bindParam(1, $id);
$stmt->execute();
$row = $stmt->fetch();
$customer = new Customer();
$customer->setIdCustomer($row['IdCustomer']);
$customer->setCustomerName($row['CustomerName']);
$customer->setPhoneNumber($row['PhoneNumber']);
$customer->setBankNumber($row['BankNumber']);
$customer->setCAddress($row['AddressC']);
$customer->setCEmail($row['EmailC']);
$customer->setPassword($row['Password']);
$customer->setCustomerStatus($row['CustomerStatus']);
$customer->setPhoto($row['Photo']);
$company = new Company();
$company->setIdCompany($row['IdCompany']);
$company->setCompanyName($row['CompanyName']);
$company->setWebsite($row['Website']);
$company->setPhone($row['Phone']);
$company->setEmail($row['Email']);
$company->setAddress($row['Address']);
$company->setLogo($row['Logo']);
$city = new city();
$city->setIdC($row['IdC']);
$city->setNameC($row['NameC']);
$customer->setCompany_IdCompany($company);
$customer->setCity_Id($city);
} catch (PDOexception $e) {
echo $e->getMessage();
die();
}
$conn = null;
return $customer;
}
and I want to display this in my customer view
<?php
if (isset($_SESSION['IdCustomer'])) {
$dao = new CustomerDao();
$id = $_SESSION['IdCustomer'];
$dataInfo = $dao->getOneCustomer($id);
echo '<div class="col-md-12">
<div id="fh5co-tab-feature-vertical" class="fh5co-tab">
<ul class="resp-tabs-list hor_1">
<li><i class="fh5co-tab-menu-icon ti-ruler-pencil"></i> Company</li>
<li><i class="fh5co-tab-menu-icon ti-paint-bucket"></i> Project & Task</li>
<li><i class="fh5co-tab-menu-icon ti-shopping-cart"></i> Proof of Payment</li>
</ul>
<div class="resp-tabs-container hor_1">
<div>
<div class="row">
<div class="col-md-12">
<h2 class="h3">Company</h2>
</div>
<div class="col-md-6">
<h2>'.$dataInfo->getCustomerName().'</h2> // i want diplay customer name
</div>
</div>
</div>
</div>
</div>
</div>
</div>';
}?>
Thank You

so, I have a solution to this problem. I was wrong when validate data login in the customer login session

Related

Php pdo: Showing topics out database

I need some help finding out how to show all the topics from the mysql (phpmyadmin) database on my website.
This is how it looks like now
The code for that is:
<section class="col-md-4 connectedSortable">
<!-- TABLE: LATEST ORDERS -->
<div class="box box-info">
<div class="panel panel-default">
<div class="panel-heading main-color-bg">
<h3 class="panel-title">Topics</h3>
</div>
<div class="container-fluid">
<div class="row content">
<ul class="nav nav-pills nav-stacked">
<li class="active">Home</li>
<li>Friends</li>
<li>Family</li>
<li>Photos</li>
</ul><br>
</div>
</div>
</div>
</div><!-- /.box -->
</section><!-- right col -->
I want this list to be the list of topics out of the database
How the database looks like
this is my config.php:
<?php
date_default_timezone_set('Europe/Amsterdam');
error_reporting(E_ALL & ~ E_DEPRECATED);
ini_set('display_errors','ON');
$CONFIG = array();
$CONFIG['root'] = '####';
$CONFIG['rootwebsite'] = '####';
$CONFIG['website'] = '####';
$CONFIG['dbhost'] = 'localhost';
$CONFIG['dbuser'] = '####';
$CONFIG['dbpass'] = '####';
$CONFIG['dbdatabase'] = 'tom';
?>
What I tried:
class Forum
{
private $dbh; //dbh = database handler.
public function __construct($database)
{
$this->dbh = $database;
}
/* function that gets the main forum board */
public function getForum()
{
$query = $this->dbh->prepare('SELECT * FROM `topics` ORDER BY `id` ASC');
$query->execute();
$results = $query->fetchAll();
foreach( $results as $row ){
print_r( $row );
}
}
}
Here goes from the PDO perspective:
<?php
// Connect to DB
try {
$yourdsn = 'mysql:dbname=<YOURDBNAME>;host=<YOURDBHOST>;
$data = new PDO($yourdsn, $youruser, $yourpassword);
$data->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$data->exec("set names utf8");
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
Then query your table
$sql = "SELECT * FROM topics ORDER BY id DESC";
$topics = $data->prepare($sql);
$topics->execute();
$tops = $topics->fetchAll(PDO::FETCH_OBJ);
Finally loop results in HTML template
<? foreach($tops as $top):?>
<h1><?=$top->onderwerp?></h1>
<p><?=$top->omschrijving?></p>
<? endforeach;?>

PHP MVC Send object variable with href

Building a school management system using only PHP and PDO - college project.
Now I'm using MVC, and I'm having trouble sending information from one view to another.
This is the View I want information from
<?php
include_once 'model/student.php';
include_once 'model/courses.php';
$selected = new Student();
$students = Student::getAllStudents();
$selected2 = new Course();
$courses = Course::getAllCourses();
?>
<div>
<div class="col-lg-6">
<span style="font-size: 24px;"> <u>Students</u> - <button style="color:black;width: 30px;height: 35px;">+</button></span>
<br>
<hr>
<?php /* this is where I have the problem, the href attribute - I'm not sure I am sending the information correctly */
foreach($students as $stu){
?> <div> Student Name: <a href='? controller=student&action=showstudent&student_id=<?php echo $stu->id ?>'> <?php echo $stu->name ?> </a></div><br>
<div> Student Phone: <?php echo $stu->phone ?> </div><br> <hr> <?php
}
?>
</div>
<div class="col-lg-6">
<span style="font-size: 24px;"> <u>Courses</u> - <button style="color:black;width: 30px;height: 35px;">+</button></span>
<br>
<hr>
<?php
foreach($courses as $cur){
echo "<span><a href='#' ><b><u><i>" .$cur->name . "</i></u></b></a></span></br><hr>";
}
?>
</div>
</div>
These are the Controller and Model
<?php
class StudentController {
public $student_model;
public function __construct() {
$this->student_model= new Student();
}
public function showstudent($id) {
$find = $this->student_model->findStudentById($id);
if($find==TRUE){
require_once 'views/pages/container/student_into_container.php';
}
else{
echo "error";
}
}
}
Model
<?php
require_once 'connection.php';
class Student{
public $name;
public $phone;
public $email;
public $img;
public $id;
public function __construct() {
}
public static function getAllStudents(){
$students = [];
$db = Db::getInstance();
$req = $db->query('SELECT id, name, phone, email, image FROM students');
$students_info = $req->fetchAll();
foreach ($students_info as $student_info){
$stu = new Student;
$stu->id = $student_info['id'];
$stu->name = $student_info['name'];
$stu->phone = $student_info['phone'];
$stu->email = $student_info['email'];
$stu->img = $student_info['image'];
array_push($students, $stu);
}
return $students;
}
public function findStudentById($id){
$db = Db::getInstance();
$req = $db->prepare('SELECT * FROM student WHERE id = :id');
$req->execute(array('id' => $id));
$student = $req->fetch();
return $student;
}
}
And this is the view I want to get the $id from a student I found
and show all his value fields - this is the student_into_container.php from the StudentController page
<?php
require_once 'connection.php'
?>
<div style="" class="">
<div class="col-lg-4 ">
<?php
require_once 'views/pages/container/student_courses_aside.php';
?>
</div>
<div style="color: black;" class="col-lg-8 blackboard ">
<div class="blackboard-container" style="margin-top:10px;font-size:36px;">
<?php foreach($students as $stu){
echo "<span> Student Name: <a href='#'>". $stu->name . "</a></span></br>";
echo "<span> Student Phone: " . $stu->phone . "</span></br> <hr>";
}
?>
</div>
</div>
</div>
Totally lost here, any help would help.
In short?
Show in once view an information sent from another view with an href attribute

How to retrieve image from DB using PHP

I'm using the following code retriever image from DB along with other attributes i.e Full Name, Mobile No. etc.But it is showing an empty image box.
require 'database.php';
$MobileNo = null;
if ( !empty($_GET['MobileNo'])) {
$MobileNo = $_REQUEST['MobileNo'];
}
if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php
$row = $data or die("line 44 not working");
$s=$row['Picture'];
echo $row['Picture'];
echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
?>
</label>
</div>
</div>
You have disconnected the database before fetching $row = $data or die("line 44 not working");
You need to disconnect it after the variable is set.
if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);
$row = $data or die("line 44 not working");
$s=$row['Picture']; //This is where you make the change.
echo $row['Picture'];
Database::disconnect(); //Now disconnect
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php
echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
?>
</label>
</div>
</div>

How do I join tables for a search query in Codeiginter

Hi I have the following function that search uses to find information:
function get_search(){
$property_location = $this->input->post('property_location');
$property_bedroom = $this->input->post('property_bedroom');
$property_bathroom = $this->input->post('property_bathroom');
$property_status = $this->input->post('property_status');
$property_type = $this->input->post('property_type');
$this->db->like('property_location',$property_location);
$this->db->like('property_beds',$property_bedroom);
$this->db->like('property_bath',$property_bathroom);
$this->db->like('property_state',$property_status);
$this->db->like('property_type',$property_type);
$query = $this->db->get('property');
error_log($this->db->last_query());
return $query->result();
}
How would I join another table say property_images to the search so that data is included in the result?
Here is my view:
<div class="container">
<div class="page-header">
<h4>Your search returned the following result(s):</h4>
</div>
<?php foreach ($results as $item): ?>
<div class="row">
<div class="col-md-3">
<div class="thumbnail">
<img
src="<?php echo base_url() . 'data/images/property_images/' . $item->image_name; ?>"
class="img-responsive">
</div>
</div>
<div class="col-md-9">
<h4 style="margin-top: 0;">
<?php echo $item->property_name; ?>
</h4>
<p><?php echo $item->property_description;?></p>
<p>Location: <?php echo $item->property_location ?> | Price: R<?php echo $item->property_price ?></p>
</div>
</div>
<hr>
<?php endforeach; ?>
</div>
You can use join in your query:
function get_search(){
$property_location = $this->input->post('property_location');
$property_bedroom = $this->input->post('property_bedroom');
$property_bathroom = $this->input->post('property_bathroom');
$property_status = $this->input->post('property_status');
$property_type = $this->input->post('property_type');
$this->db->like('property_location',$property_location);
$this->db->like('property_beds',$property_bedroom);
$this->db->like('property_bath',$property_bathroom);
$this->db->like('property_state',$property_status);
$this->db->like('property_type',$property_type);
$this->db->join('property_images','property.property_image_id=property_images.property_image_id'); //add this line in your code
$query = $this->db->get('property');
error_log($this->db->last_query());
return $query->result();
}
Hope it will help you....
You can do it using join() method of active records class you are using.
join($table, $cond[, $type = ''[, $escape = NULL]])
Parameters:
$table (string) – Table name to join
$cond (string) – The JOIN ON condition
$type (string) – The JOIN type
$escape (bool) – Whether to escape values and identifiers
Returns:
CI_DB_query_builder instance (method chaining)
Return type:
CI_DB_query_builder
Adds a JOIN clause to a query.
Reference
In your example:
$this->db->like('property_location',$property_location);
$this->db->like('property_beds',$property_bedroom);
$this->db->like('property_bath',$property_bathroom);
$this->db->like('property_state',$property_status);
$this->db->like('property_type',$property_type);
$this->db->like('property_images.imageField', $imageFieldValue); // Observe change here.
$query = $this->db->get('property');
$this->db->join('property_images','property.your_id_field = property_images.your_id_field'); // Observe change here.

Background color from table column

I have a hex color set inside of a table column and trying to set it to a div background but it will not apply it:
<?php
$user = $_SESSION['user'];
try{
$results = $dbh->query("SELECT *
FROM cat_List
INNER JOIN user_cat_link_table
ON cat_List.Cat_ID = user_cat_link_table.Cat_ID
WHERE user_cat_link_table.UserID = $user");
}catch(Exception $e) {
echo $e->getMessage();
die();
}
$docs = $results->fetchAll(PDO::FETCH_ASSOC);
foreach($docs as $docs){
echo '
<a href="catView.php?cat_id='.$docs["cat_id"].'">
<div class="indexBox" style="background-color="'.$docs["cat_color"].'">
<div class="indexBoxHeader">
<i class="fa fa-users" style="font-size: 2em;"></i></div>
<div class="indexBoxFooter">
<p>'.$docs["cat_title"].'</p>
</div>
</div>
</a>
';}
?>
If I echo the cat_color out it return the value #000 which is the value in the table? Is my syntax wrong?
It should be style="background-color:'.$docs["cat_color"].'"

Categories