Hi, I am new to woocommerce. I made a website and upgraded the woocommerce version recently, after that their are two add to cart modules on single product page. I can’t remove it. I am using divi theme, please help.
Category: PHP
Category Added in a WPeMatico Campaign
PHP Rest API – get header parameter
I have created a basic rest api using php which is working.
I want to add a header customer_id to the request
When I do this I’m not seeing it output in the headers of the api call
$header = apache_request_headers();
$AuthKey=$header['Auth-Api-Key'];
$customerId=$header['customer_id'];
If I print_r($AuthKey) as a test I can see the Auth-Api-Key value. However print_r($customerId) is blank
Post data using php
I’m new in API development, I made an API to fetch and store data, I can fetch data without any problem, but everything changes when I try to store data, when I send the data to store it returns [{"success":"0"}]. In the beginning it worked well, it accepted to store data, but suddenly everything changed. I’ve tried everything, compare new code with the old, change the code, tables, but even so it always returns [{"success":"0"}] after comparing both (old and new) code I couldn’t see much difference. What could I be doing wrong?
Insert data:
function insertloin()
{
if(isset($_POST["loincode"]))
{
$form_data = array(
':loincode' => $_POST["loincode"],
':code' => $_POST["code"],
':specie' => $_POST["specie"],
':grade' => $_POST["grade"],
':vesselname' => $_POST["vesselname"],
':type' => $_POST["type"],
':productformat' => $_POST["productformat"],
':dateprocessed' => $_POST["dateprocessed"],
':datebb' => $_POST["datebb"],
':projectcode' => $_POST["projectcode"],
':netweight' => $_POST["netweight"],
':producttype' => $_POST["producttype"],
':oldoc' => $_POST["oldoc"]
);
$query = "
INSERT INTO loins
(loincode, code, specie, grade, vesselname, type, productformat, dateprocessed, datebb, projectcode, netweight, producttype, oldoc) VALUES
(:loincode, :code, :specie, :grade, :vesselname, :type, :productformat, :dateprocessed, :datebb, :projectcode, :netweight, :producttype, :oldoc)
";
$statement = $this->connect->prepare($query);
if($statement->execute($form_data))
{
$data[] = array(
'success' => '1'
);
}
else
{
$data[] = array(
'success' => '0'
);
}
}
else
{
$data[] = array(
'success' => '0'
);
}
return $data;
}
Test:
if($_GET["action"] == 'insertloin')
{
$data = $api_object->insertloin();
}
Action:
if(isset($_POST["action"]))
{
if($_POST["action"] == 'insertloin')
{
$form_data = array(
'loincode' => $_POST["loincode"],
'code' => $_POST["code"],
'specie' => $_POST["specie"],
'grade' => $_POST["grade"],
'vesselname' => $_POST["vesselname"],
'type' => $_POST["type"],
'productformat' => $_POST["productformat"],
'dateprocessed' => $_POST["dateprocessed"],
'datebb' => $_POST["datebb"],
'projectcode' => $_POST["projectcode"],
'netweight' => $_POST["netweight"],
'producttype' => $_POST["producttype"],
'oldoc' => $_POST["oldoc"]
);
$api_url = "http://192.168.85.160/API/v2/api/test_api.php?action=insertloin";
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
$result = json_decode($response, true);
foreach($result as $keys => $values)
{
if($result[$keys]['success'] == '1')
{
echo 'insert';
}
else
{
echo 'error';
}
}
}
Please, help me find the bug.
Kind regards,
Abd
How to specify which column the foreign key should be based on in voyager?
Codeigniter 3.11 problems with foreach and inserts
im trying to learn codeigniter and im passing an old php project to codeigniter but im having problem with my routine in foreach, because if i run var_dump it is giving the value but when im sending to the insert it is giving a value of zero, my view and controller it is fine, but the foreach routine it is giving me a problem, any help would be appreciated:
Model example
public function addcustcfdi($data) {
//Buscamos la calle si existe tomamos el ID si no, insertamos
$this->db->select('id');
$this->db->from('facturacion_calle');
$this->db->where('calle',$data["calle"]);
$query= $this->db->get();
foreach ($query->result_array() as $row)
{
$row['id'];
}
if ($row['id'] == 0)
{
$queryinsert = $this->db->query("INSERT INTO facturacion_calle (calle) VALUES ('".$data["calle"]."'')");
}
$this->db->select('id');
$this->db->from('facturacion_calle');
$this->db->where('calle',$data["calle"]);
$query= $this->db->get();
foreach ($query->result_array() as $row)
{
$id_calle = $row['id'];
}
The weird issue it is in Core PHP it works fine with this syntax:
//Buscamos la calle si existe tomamos el ID si no, insertamos
$query = sprintf("SELECT id FROM $tbl_2 WHERE calle='%s'",$calle);
$result = $db->query($query);
if (!$result || ! ($row = mysqli_fetch_assoc($result))) {
$query = sprintf ("INSERT INTO $tbl_2 (calle) VALUES ('%s')",$calle);
$db->query($query);
}
$query = sprintf("SELECT id FROM $tbl_2 WHERE calle='%s'",$calle);
$result = $db->query($query);
while ($row = mysqli_fetch_assoc($result))
{
$id_calle = $row['id'];
}
Hope that someone can help me out, warm regards!
Is anybody know how to make a correct links(full path) to categories in case with multimenu below?
Is anybody know how to make a correct links(full path) to categories in case with multimenu below?Is anybody know how to make a correct links(full path) to categories in case with multimenu below?Is anybody know how to make a correct links(full path) to categories in case with multimenu below?Is anybody know how to make a correct links(full path) to categories in case with multimenu below?
<style>
nav ul
{
list-style: none;
padding: 0;
text-align:center;
}
nav li
{
background-color: rgba(0,100,0,0.5);
position: relative;
display: inline-block;
}
nav li:hover
{
background-color: rgba(100,0,0,0.5)
}
nav a
{
display:block;
padding: 0.5em;
text-decoration: none;
color: rgba(0,0,100,0.9);
}
nav ul ul
{
display: none;
position: absolute;
}
nav li:hover > ul
{
display: block;
}
nav ul ul ul
{
left: 100%;
top: 0;
}
nav > ul > li > ul > li
{
min-width: 100%;
}
</style>
<?php
function is_multidimensional(array $array) {
return count($array) !== count($array, COUNT_RECURSIVE);
}
function printArrayList($array, $last)
{
$pathstring ="";
echo "<ul>n";
foreach ($array as $k => $v)
{
$path[]=$k;
if (is_array($v))
{
$path[]=$last; $fullPath = implode("/", $path);
echo "<li><a href=".$fullPath.">" . $k . "</a>n"; //echo "<li><a href=''>" . $k . "</a></li>n";
if (is_multidimensional($v)) { printArrayList($v, $k); } else { }
continue;
}
if (strpos($k, "option")>0) {
} else { echo "<li>" . $k . " " . $v . ""; } // } else { echo "<li>" . $k . " " . $v . "</li>"; }
}
echo "</ul>n";
}
$menu = array(
'Cat1' => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"ITEMS1" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "111",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
"ITEMS2" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
) ,
'Cat2' => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"ITEMS1" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
"ITEMS2" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
) ,
'Cat2' => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"ITEMS1" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
"ITEMS2" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
'FORCATEGORY_NUMBER3_option' => "3",
"Apples" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
"Banans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
"BigBanans" => array(
'FORCATEGORY_NUMBER1_option' => "1",
'FORCATEGORY_NUMBER2_option' => "2",
),
),
),
) ,
);
?>
<nav>
<?PHP printArrayList($menu, $last="");
?>
</nav>
WAMP Server Connection error: SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO)
Please I need help with the code below; I get
Connection error: SQLSTATE[HY000][1045] Access denied for user ‘root’@’localhost’ (using
password: NO).
After this error, I get another below it that shows:
Fatal error: Uncaught Error: Call to a member function prepare() on
null in C:wamp64wwwuser_loginobjectsuser.php on line 41
Then the third one shows:
Error: Call to a member function prepare() on null in
C:wamp64wwwuser_loginobjectsuser.php on line 41
I am still new to working with class; Please help me out. Thanks
Please find my code below:
<?php
// used to get mysql database connection
class Database{
// specify your own database credentials
private $host = "localhost";
private $db_name = "phplogin";
private $username = "root";
private $password = "";
public $conn;
// get the database connection
public function getConnection(){
$this->conn = null;
try{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
}catch(PDOException $exception){
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
Additional Code based on the error
<?php
// 'user' object
//require_once './config/database.php';
class User{
// database connection and table name
private $conn;
private $table_name = "users";
// object properties
public $id;
public $firstname;
public $lastname;
public $email;
public $contact_number;
public $address;
public $password;
public $access_level;
public $access_code;
public $status;
public $created;
public $modified;
// constructor
public function __construct($db){
$this->conn = $db;
}
// check if given email exist in the database
function emailExists(){
// query to check if email exists
$query = "SELECT id, firstname, lastname, password, access_level, status
FROM " . $this->table_name . "
WHERE email = ?
LIMIT 0,1";
// prepare the query
$stmt = $this->conn->prepare($query);
// sanitize
$this->email=htmlspecialchars(strip_tags($this->email));
// bind given email value
$stmt->bindParam(1, $this->email);
// execute the query
$stmt->execute();
// get number of rows
$num = $stmt->rowCount();
// if email exists, assign values to object properties for easy access and use for php sessions
if($num>0){
// get record details / values
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// assign values to object properties
$this->id = $row['id'];
$this->firstname = $row['firstname'];
$this->lastname = $row['lastname'];
$this->access_level = $row['access_level'];
$this->password = $row['password'];
$this->status = $row['status'];
// return true because email exists in the database
return true;
}
// return false if email does not exist in the database
return false;
}
// create new user record
function create(){
// to get time stamp for 'created' field
$this->created=date('Y-m-d H:i:s');
// insert query
$query = "INSERT INTO
" . $this->table_name . "
SET
firstname = :firstname,
lastname = :lastname,
email = :email,
contact_number = :contact_number,
address = :address,
password = :password,
access_level = :access_level,
status = :status,
created = :created";
// prepare the query
$stmt = $this->conn->prepare($query);
// sanitize
$this->firstname=htmlspecialchars(strip_tags($this->firstname));
$this->lastname=htmlspecialchars(strip_tags($this->lastname));
$this->email=htmlspecialchars(strip_tags($this->email));
$this->contact_number=htmlspecialchars(strip_tags($this->contact_number));
$this->address=htmlspecialchars(strip_tags($this->address));
$this->password=htmlspecialchars(strip_tags($this->password));
$this->access_level=htmlspecialchars(strip_tags($this->access_level));
$this->status=htmlspecialchars(strip_tags($this->status));
// bind the values
$stmt->bindParam(':firstname', $this->firstname);
$stmt->bindParam(':lastname', $this->lastname);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':contact_number', $this->contact_number);
$stmt->bindParam(':address', $this->address);
// hash the password before saving to database
$password_hash = password_hash($this->password, PASSWORD_BCRYPT);
$stmt->bindParam(':password', $password_hash);
$stmt->bindParam(':access_level', $this->access_level);
$stmt->bindParam(':status', $this->status);
$stmt->bindParam(':created', $this->created);
// execute the query, also check if query was successful
if($stmt->execute()){
return true;
}else{
$this->showError($stmt);
return false;
}
}
public function showError($stmt){
echo "<pre>";
print_r($stmt->errorInfo());
echo "</pre>";
}
}
?>
$sstmt->get_result()->fetch_assoc(); error: Call to undefined method mysqli_stmt::get_result() [duplicate]
This is not a duplicate question, as in my case i do not know how to implement the responses here
Call to undefined method mysqli_stmt::get_result
using bind_result() & fetch()! or if i have to install something on my host.
I am getting the error from my code here:
$sql = $sql . " LIMIT 1";
$sstmt = executeQuery($sql, $conditions);
$records = $sstmt->get_result()->fetch_assoc();
return $records;
How to implement this fix in this case, i am new to php
How to use seperate js files in Laravel Blade
I’m trying to have different JS files for each Blade View in Laravel to help keep the project structure clean.
My problem is, when I try to access a function from that JS file in a Blade view, the console returns an error of:
Uncaught ReferenceError: myFunc is not defined at HTMLButtonElement.onclick
But the file is there and it logs the console message from that js file.
Here are my files and structure:
resources/js/index.js
console.log("Hello from index js");
function myFunc() {
console.log("Hello");
}
resources/views/layout/master.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
@yield('content')
{{-- @yield('js') --}}
@stack('js')
</body>
</html>
resources/views/index.blade.php
@extends('layout.master')
@section('content')
<h1>Works</h1>
<button onclick="myFunc()">Click</button>
@endsection
@push('js')
<script src="{{ asset('js/index.js')}}"></script>
@endpush
webpackmix.mix.js
const mix = require("laravel-mix");
mix.js("resources/js/app.js", "public/js").postCss(
"resources/css/app.css",
"public/css",
[
//
]
);
mix.js("resources/js/index.js", "public/js");
Could not find .php file in /var/www in apache server
I’m using Vagrant provider for server, now look at my directories :
in my system:
https://i.stack.imgur.com/XCXIm.png
vagrant-site
-Project(/var/www)
–public (/var/www/html)
—index.php
now I created a sample .php file in Project folder then when I run vagrant and logged in vagrant ssh when I cd to /var/www ,that .php file doesn’t exist there and I could not work with
include __DIR__ . '/../count.html.php';
this line of code not working because this file doesn’t exist in /var/www but exist in my system
Magento installation problem using the zip file with out xamp
I went through this website and download the magento zip and unzip it.
Then I went to chrome browser and type the localhost:Magento
and press enter but it not working, can some one please help me here
Thanks in advance
Symfony how to include controller on base.html.twig
I have a small question, I’m new to symfony, I created a controller and a menu template that I want to integrate into my base.html.twig.
I absolutely need the controller to be called because I am testing to know if the session variable is empty or not.
{% block menu %}
{% include 'menu/index.html.twig' %}
{% endblock %}
<body>
{% block body %}{% endblock %}
</body>
So I tried this (it works perfectly BUT it didn’t call my controller so when I do my test on session it won’t work….)
I searched but I can’t include the controller instead of the template…
thanks in advance
call or activate the php function by html button or javascript [duplicate]
I want to call the php function by html button or javascript code.
for example if I click a button, a php function should display or do some function. I know ajax is the only way to do this, but I could not understand the ajax code for simply call the function,
so please anyone give a simple example ajax code to control the php function by html button. and please do not give any code with jquery or any other library, because I not yet learn any libraries for php or javascript.
Facebook Graph API display feed content on website
I took over my site to update it and I saw that my facebook feed is no longer displayed, I inquired and apparently new permissions are now required.
I would simply like to display on my site the latest facebook posts
I don’t have a facebook login on my site, it’s useless to me
I did some tests with postman and now I’m being asked for pages_read_engagement and Page Public Content Access permissions
here is my postman link
and the result:
{
"error": {
"message": "(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage -pages and https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS for details.",
"type": "OAuthException",
"code": 10,
}
}
when I asked for Page Public Content Access permission, facebook tells me that my use case does not require this permission, I don’t know what to do now, do you have any idea?
thank you
How to check if a record in a table also exists in another table or not in MYSQL
I have two tables “order_manager” and “aamarpay”. Both the table has a column named “transaction_id”. It is a 10 character long randomly generated string. I’m trying to verify if a payment is made successfully or not. If the payment is successful the transaction_id from “order_manager” table would also exist in the “aamarpay” table. Here are the structures of the tables:
order_manager
aamarpay
If the condition returns true then I would update “payment_status” from “order_manager” table to “successful”.

