How to fix zsh:command not found : php while installing composer?

I want to install composer in my macbook pro ( MacOS Monterey version 12.1 , chip M1 pro). How I install it (below):
1.first I open the terminal in macbook and paste these :

Mac@Mine-MacBook-Pro ~ % php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
php -r “if (hash_file(‘sha384’, ‘composer-setup.php’) === ‘906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
php composer-setup.php
php -r “unlink(‘composer-setup.php’);”

I got the command line from this website :Composer Download

  1. press Enter
  2. Then not success with show message on my terminal :

zsh: command not found: php
zsh: command not found: php
zsh: command not found: php
zsh: command not found: php

  1. please help fix it for me. I need to install composer and install laravel for my laptop.

big thanks,

Login With Google customer login data Database table Management

My website is a small business listing website. People can register with their email id and post their business in my website. I gave a customer id to people at the time of registration which is an auto AUTO INCREMENT key in my “user table”. The same key is given to userId column of “business” table at the time for business posting for knowing which customer upload data and for future editing of business listing of that registered person. Now I am trying to implement “Login with Google” feature in my website for easy customer registration. But I have no idea to manage user who coming from “Login with Google” feature.
I have an idea but which is good or Not , i am not knowing. Keeping separate SQL table “user_google”, where also an AUTO INCREMENT key starting from 10000000 to manage multiple customer id problem. When I saw userId>10000000, I can understand which is coming from “Login with Google”.
In my old table “user” there is also a column for “password”. But i think there is no such column in “user_google” table as I think.
Also one doubt is there, if already one customer login with google feature , and uploaded his business, in future if he trying to register through registration form in my website, how can I handle this?. How many customers can use login with google feature in my website per day? My website is PHP and SQL website.

PHP: search array(A) value in array(B) and get 2nd “column” value

I have Array(A) = ('red','green')

and

Array(B) 
( array('colour' => "red", 'name_cz' =>"cervena"),
array('colour' => "green", 'name_cz' =>"zelena"),
array('colour' => "blue", 'name_cz' =>"modra"),
array('colour' => "yellow", 'name_cz' =>"zluta")
)

I need to take every value of Array(A), compare it with Array(B) colour values and if it finds get its name_cz value…

so the output of the example should be like $result = (array("cervena", "zelena");

Thanks for help, subii

How to route every API request through own proxy?

On my LAMP server, I have a Javascript, JQuery based app, which makes requests to a remote API and displays its responses. As long as only I use the app, everything is OK. But now I must open this app to multiple users, and if the API gets multiple requests from the same IP, it bans the IP.

What is the way to route each request through its own proxy address? I have many working proxies as a list, and a proxy gateway, which can route multiple requests.

A simple example or just a correct keyword to search would be enough as an answer.

Ajax doesn’t call javascript function correctly

php) that via ajax calls a table from another page (temp2.php).
If I execute temp2.php via browser directly it works so the function works. Infact the function validate the input number be assign red or green colour.

temp2.php is here:
https://jsfiddle.net/cg3Lhstz/

if i all temp2.php from temp1.php via ajax, I can see the input field, but when i type inside it doesn’t validate so the function is not correctly executed and in the browser console i have the following error:

temp1.php:1 Uncaught ReferenceError: checkValid is not defined
    at HTMLInputElement.onkeyup (temp1.php:1:1)

temp1.php has the following code:

<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
</head>
<body>
    <div id="trc"></div>
</body>
    
<script>
$("#trkview").show();

  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (this.readyState==4 && this.status==200) {
      document.getElementById("trc").innerHTML=this.responseText;
    }
  }
  xmlhttp.open("POST","cc_temp2.php");
  xmlhttp.send();

any help ? thanks a lot

Shinyproxy – redirect loop after login by oauth openid

after upgrade ShinyProxy I have login problem.

I use OIDC with my own auth server to login to shiny. Everythink work well on 2.3.1, after update to 2.6.1 I have redirection loop. In my shinyproxy.log I can see:

Using generated security password: 6b5a0b37-7d15-441b-82c2-7b521390f98c
…
2022-01-28 11:10:53.561 WARN 1617 — [main] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode ‘HTML5’ is deprecated. Using Template Mode ‘HTML’ instead.
2022-01-28 11:10:53.566 INFO 1617 — [main] e.o.c.stat.StatCollectorFactory : Enabled. Sending usage statistics to jdbc:mysql://xx.xxx.xx.xxx:3306/admdev_test.
2022-01-28 11:10:53.875 INFO 1617 — [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService
2022-01-28 11:10:53.876 INFO 1617 — [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘taskExecutor’
2022-01-28 11:10:54.198 INFO 1617 — [main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2022-01-28 11:10:54.727 INFO 1617 — [main] o.s.l.c.support.AbstractContextSource : Property ‘userDn’ not set - anonymous context will be used for read-write operations
2022-01-28 11:10:54.983 INFO 1617 — [main] io.undertow : starting server: Undertow - 2.2.8.Final
2022-01-28 11:10:55.007 INFO 1617 — [main] org.xnio : XNIO version 3.8.4.Final
2022-01-28 11:10:55.033 INFO 1617 — [main] org.xnio.nio : XNIO NIO Implementation Version 3.8.4.Final
2022-01-28 11:10:55.145 INFO 1617 — [main] org.jboss.threads : JBoss Threads version 3.1.0.Final
2022-01-28 11:10:55.231 INFO 1617 — [main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port(s) 8080 (http)
2022-01-28 11:10:55.378 INFO 1617 — [main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2022-01-28 11:10:55.378 INFO 1617 — [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 141 ms
2022-01-28 11:10:55.397 INFO 1617 — [main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path ‘/actuator’
2022-01-28 11:10:55.471 INFO 1617 — [main] io.undertow : starting server: Undertow - 2.2.8.Final
2022-01-28 11:10:55.517 INFO 1617 — [main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port(s) 9090 (http)
2022-01-28 11:10:55.537 INFO 1617 — [main] e.o.c.util.StartupEventListener : Started ShinyProxy 2.6.0 (ContainerProxy 0.8.10)
2022-01-28 11:10:55.537 INFO 1617 — [main] e.o.c.service.AppRecoveryService : Recovery of running apps disabled
2022-01-28 11:11:19.442 INFO 1617 — [XNIO-1 task-1] io.undertow.servlet : Initializing Spring DispatcherServlet ‘dispatcherServlet’
2022-01-28 11:11:19.443 INFO 1617 — [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’
2022-01-28 11:11:19.451 INFO 1617 — [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
2022-01-28 11:11:42.879 INFO 1617 — [XNIO-1 task-1] e.o.containerproxy.service.UserService : User logged in [user: [email protected]]
2022-01-28 11:11:42.880 INFO 1617 — [XNIO-1 task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting…
2022-01-28 11:11:44.122 ERROR 1617 — [XNIO-1 task-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.

java.sql.SQLException: Access denied for user ‘admdev’@‘Debian-95-stretch-64-LAMP’ (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.25.jar!/:8.0.25]

2022-01-28 11:11:44.127 ERROR 1617 — [XNIO-1 task-1] io.undertow.request : UT005023: Exception handling request to /login/oauth2/code/shinyproxy

java.lang.reflect.UndeclaredThrowableException: Failed to invoke event listener method
HandlerMethod details:
Bean [eu.openanalytics.containerproxy.stat.impl.JDBCCollector]
Method [public void eu.openanalytics.containerproxy.stat.impl.AbstractDbCollector.onUserLoginEvent(eu.openanalytics.containerproxy.event.UserLoginEvent) throws java.io.IOException]
Resolved arguments:
[0] [type=eu.openanalytics.containerproxy.event.UserLoginEvent] [value=eu.openanalytics.containerproxy.event.UserLoginEvent[source=eu.openanalytics.containerproxy.service.UserService@751817d9]]

at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:322) ~[spring-context-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]

information about mysql user (admdev) i have only in m server side. Settings for my mysql is ok so firstly i have info about successful login. I dont know why it show this error then. Also everything work ok when I downgrade to 2.3.1 i dont need to change anything in my server side.
Maybe anyone know what can i do to fix it?

PHP SSH2 echo to file for stop session

I want to create a stop.sh file for stopping screen session.

$test = "screen_name";

This is the command:
kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')

And i want to create this file with php ssh2_exec like this:

ssh2_exec($connection, "echo 'kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')' > /home/test/stop.sh");

But i got this:

sh: 1: Syntax error: "(" unexpected

I tried:

kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')

but not working..

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

enter image description here

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

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;
    }

}

?>

Error message screenshot

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>";
}

}

?>