Call to undefined function db_query() in cs cart - cs-cart

i am working now cs cart framework.i am write now insert query ,Here is my code there.
if($_REQUEST['finance'] !=''){
$finance=$_REQUEST['finance'];
$data = array();
$data = $finance;
$feature_id = db_query('INSERT INTO ?:bootsgrid_pay4later_finance ?e',
$data);
echo "success";
exit;
}
but i got e response
Fatal error: Call to undefined function db_query() in
How can i fix this issue.please help me.

Related

Call to undefined method App\Product::getProductStock()

BadMethodCallException
Call to undefined method App\Product::getProductStock()
This error occurred while accessing the model function in controller
My Controller
$user_id = Auth::user()->id;
$user_email = Auth::user()->email;
// To prevent out of stock material from ordering
$userCart=DB::table('cart')->where('user_email',$user_email)->get();
// echo "<pre>"; print_r($userCart); die;
foreach ($userCart as $cart) {
$product_stock= Product:: getProductStock($cart->product_id,$cart->size);
echo $product_stock;
if ($product_stock==0) {
return redirect('/cart')->with('flash_message_error','Product is Stock sold out. Buy another product');
}
if ($Cart->quantity>$product_stock) {
return redirect('/cart')->with('flash_message_error','Reduced product stock & Try Again');
}
}
Model
public static function getProductStock($product_id,$product_size)
{
$getProductStock=ProductsAttribute::select('stock')->where(['product_id'=>$product_id,'size'=>$product_size])->first();
return $getProductStock->stock;
}
I think you product retrieving approach is not the best.
To get the product you should use this approach:
$product = Product::find($cart->product_id);
And to retrieve the stock should be:
$product_stock = $product->getProductStock($product->id, $cart->size);

Call to a member function setPath() on a non-object in laravel

In my Laravel web application, getting error like "Call to a member function setPath() on a non-object" while using pagination.
My code is
In model,
public function scopegetApartments()
{
$list1 = DB::table('properties')->orderBy('id','DESC')->paginate(1);
$list = array();
foreach($list1 as $listeach){
$imgs = DB::table('property_images')->where('property_id',$listeach->id)->get();;
$images = array();
foreach($imgs as $img){
array_push($images, $img->image);
}
$lists = array(
'id'=>$listeach->id,
'name'=>$listeach->name,
'rent'=>$listeach->rent,
'shortdescription'=>$listeach->shortdescription,
'images'=>$images,
);
array_push($list, $lists);
}
if(count($list)>0){
return $list;
}else{
return '[]';
}
}
In view,
$apartmentlist->setPath('serviceapartments');
echo $apartmentlist->render();
How to resolve this problem?

I get the CI_DB_mysqli_driver::row_array() in Codeigniter

I get the CI_DB_mysqli_driver::row_array() error when trying to display a cell value.
This is my model
function list_get($id){
$this->load->database();
$query = $this->db-> select('*')
->from('lists')
->join('list_items', 'list_items.items_list_id = lists.list_id')
->where('items_list_id', $id);
return $query->row_array();
}
The error appears when I try to echo it to the view <?echo $query['list_by'];?>

Trying to get property of non-object laravel?

I am a beginner.
I'm trying to fix, i think i need help.
-This is code Controller
if(Input::hasFile('image')){
$dest = 'media/images/product/';
$name = str_random(6).'_'.Input::file('image')->getClientOriginalName();
//$resize =
Input::file('image')->move($dest,$name);
}
$loaispname = Input::get('loaispname');
$loaisp = new Loaisp;
$datas = $loaisp->getidloaisp($loaispname);
$idloaisp = $datas->id;
$item = new Sanpham;
$item->loaisp_id = $idloaisp;
$item->sanpham_name = Input::get('sanpham');
$item->sanpham_img = $name;
$item->sanpham_tieude = Input::get('tieude');
$item->sanpham_gia = Input::get('gia');
$item->sanpham_chitiet = Input::get('chitiet');
$item->sanpham_vitri = Input::get('vitri');
$item->save();
return Redirect::to('admin/dsachsanpham')->with('thanhcong','Saved');
-This is code Model
public function getidloaisp($loaispname){
//return Loaisp::where('loaisp_name','=',$loaispname)->get();
return DB::table('loaisp')->where('loaisp_name',$loaispname)->first();
}
-this is Error
ErrorException (E_UNKNOWN)
Trying to get property of non-object
Open: E:\xampp\htdocs\www\daunhot\app\controllers\AdminController.php
$loaispname = Input::get('loaispname');
$loaisp = new Loaisp;
$datas = $loaisp->getidloaisp($loaispname);
$idloaisp = $datas->id; // This is error
$item = new Sanpham;
When you see this error there could be two error: You got nothing back with your query(DB::table('loaisp')->where('loaisp_name',$loaispname)->first();), Or you got back an array, if you are using ->get() instead of ->first() you will get this error.
Try to use a foreach on your query result, or try to use dd() function on your result so you can see if is empty or not. If it is empty that is your porblem.
Same as what the rest is saying, dump $datas before the error, maybe add '=' to your where clause in that 'getidloaisp' function. You should be able to use the one your quoted out though, that is if you change the '->get()' to '->first()'.
Check if you are getting 'loaispname' on Input::get by:
echo "<pre>";
print_r($loaispname);
echo "</pre>";
exit;
If you're getting your posted data then do:
echo "<pre>";
print_r($datas);
echo "</pre>";
exit;
$datas->id work with DB table is need to be the table datas and cell id, and also they are case sensitive, not use Id or other.

for listing values from db using codeigniter rest for web service

to list the values from db i have been using the followin code
model
function user_list_community($serviceName) {
$ipJson = json_encode($input);
$this->db->select('*');
$this->db->from('community');
//$this->db->where('user_id', $input['user_id']);
$query = $this->db->get();
$result = $query->result();
if (!empty($result)) {
$data['list_community']= $result;
$data['message'] = 'User details retrieved successfully.';
$status = $this->ville_lib->return_status('success', $serviceName, $data, $ipJson);
} else {
$data['message'] = 'Unable to retrieve.Please the user id';
$status = $this->ville_lib->return_status('error', $serviceName, $data, $ipJson);
}
return $status;
}
controller
function list_community_post(){
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($input, $serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
the issue am facing is am getting the values but am getting error as follows. what was the wrong am doing here. can someone help me . thanks.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: input
Filename: controllers/users.php
Line Number: 57
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: input
Filename: models/user_model.php
Line Number: 67
You are getting error because $input is not defined in the code. So you should either this:
function list_community_post(){
$input='';
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($input, $serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
or
function list_community_post(){
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
Just like it says on the tin. Your $input variable is not created anywhere, just passed as a parameter to the json_encode and user_list_community functions.
the function user_list_community($serviceName) doesn't have two arguments while you calling it with $this->user_model->user_list_community($input, $serviceName);
try function user_list_community($input, $serviceName);
And ofcourse you have to pass value for $input arguement as above said.

Resources