Skip to main content

Good day. Im trying to make a Student log in form using php and xampp to run the code. I already have a database in phpMyAdmin and I get this error [duplicate]

  • Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\attendancemonitoring\student\controller.php:58 Stack trace: #0 C:\xampp\htdocs\attendancemonitoring\student\controller.php(11): doInsert() #1 {main} thrown in C:\xampp\htdocs\attendancemonitoring\student\controller.php on line 58

My Code

<?php
require_once(LIB_PATH.DS.'database.php');
class Student {
    protected static  $tblname = "tblstudent";

    function dbfields () {
        global $mydb;
        return $mydb->getfieldsononetable(self::$tblname);

    }
    function listofstudent(){
        global $mydb;
        $mydb->setQuery("SELECT * FROM ".self::$tblname);
        return $cur;
    }
    function find_student($id="",$name=""){
        global $mydb;
        $mydb->setQuery("SELECT * FROM ".self::$tblname." 
            WHERE StudentID = {$id} OR Lastname = '{$name}'");
        $cur = $mydb->executeQuery();
        $row_count = $mydb->num_rows($cur);
        return $row_count;
    }

    function find_all_student($lname="",$Firstname="",$mname=""){
        global $mydb;
        $mydb->setQuery("SELECT * FROM ".self::$tblname." 
            WHERE Lastname = '{$lname}' AND Firstname= '{$Firstname}' AND MNAME='{$mname}'");
        $cur = $mydb->executeQuery();
        $row_count = $mydb->num_rows($cur);
        return $row_count;
    }
     
    function single_student($id=""){
            global $mydb;
            $mydb->setQuery("SELECT * FROM ".self::$tblname." 
                Where StudentID= '{$id}' LIMIT 1");
            $cur = $mydb->loadSingleResult();
            return $cur;
    }
    function select_student($id=""){
            global $mydb;
            $mydb->setQuery("SELECT * FROM ".self::$tblname." 
                Where ID= '{$id}' LIMIT 1");
            $cur = $mydb->loadSingleResult();
            return $cur;
    }
    function studAuthentication($U_USERNAME,$h_pass){
        global $mydb;
        $mydb->setQuery("SELECT * FROM `tblstudent` WHERE `StudentID`='".$U_USERNAME."'");
        $cur = $mydb->executeQuery();
        if($cur==false){
            die(mysql_error());
        }
        $row_count = $mydb->num_rows($cur);//get the number of count
         if ($row_count == 1){
         $student_found = $mydb->loadSingleResult();
            $_SESSION['StudentID']      = $student_found->StudentID; 
            // $_SESSION['ACC_USERNAME']    = $student_found->ACC_USERNAME;
            // $_SESSION['ACC_PASSWORD']    = $student_found->ACC_PASSWORD; 
            $_SESSION['Firstname']      = $student_found->Firstname; 
            $_SESSION['Lastname']       = $student_found->Lastname; 
            $_SESSION['MI']             = $student_found->Middlename; 
            $_SESSION['Address']        = $student_found->Address;  
            $_SESSION['CourseCode']     = $student_found->CourseCode;  
           return true;
         }else{
            return false;
         }
    }

     
    /*---Instantiation of Object dynamically---*/
    static function instantiate($record) {
        $object = new self;

        foreach($record as $attribute=>$value){
          if($object->has_attribute($attribute)) {
            $object->$attribute = $value;
          }
        } 
        return $object;
    }
    
    
    /*--Cleaning the raw data before submitting to Database--*/
    private function has_attribute($attribute) {
      // We don't care about the value, we just want to know if the key exists
      // Will return true or false
      return array_key_exists($attribute, $this->attributes());
    }

    protected function attributes() { 
        // return an array of attribute names and their values
      global $mydb;
      $attributes = array();
      foreach($this->dbfields() as $field) {
        if(property_exists($this, $field)) {
            $attributes[$field] = $this->$field;
        }
      }
      return $attributes;
    }
    
    protected function sanitized_attributes() {
      global $mydb;
      $clean_attributes = array();
      // sanitize the values before submitting
      // Note: does not alter the actual value of each attribute
      foreach($this->attributes() as $key => $value){
        $clean_attributes[$key] = $mydb->escape_value($value);
      }
      return $clean_attributes;
    }
    
    
    /*--Create,Update and Delete methods--*/
    public function save() {
      // A new record won't have an id yet.
      return isset($this->id) ? $this->update() : $this->create();
    }
    
    public function create() {
        global $mydb;
        // Don't forget your SQL syntax and good habits:
        // - INSERT INTO table (key, key) VALUES ('value', 'value')
        // - single-quotes around all values
        // - escape all values to prevent SQL injection
        $attributes = $this->sanitized_attributes();
        $sql = "INSERT INTO ".self::$tblname." (";
        $sql .= join(", ", array_keys($attributes));
        $sql .= ") VALUES ('";
        $sql .= join("', '", array_values($attributes));
        $sql .= "')";
    echo $mydb->setQuery($sql);
    
     if($mydb->executeQuery()) {
        $this->id = $mydb->insert_id();
        return true;
      } else {
        return false;
      }
    }

    public function update($id=0) {
      global $mydb;
        $attributes = $this->sanitized_attributes();
        $attribute_pairs = array();
        foreach($attributes as $key => $value) {
          $attribute_pairs[] = "{$key}='{$value}'";
        }
        $sql = "UPDATE ".self::$tblname." SET ";
        $sql .= join(", ", $attribute_pairs);
        $sql .= " WHERE StudentID=". $id;
      $mydb->setQuery($sql);
        if(!$mydb->executeQuery()) return false;    
        
    }

   public function studupdate($id=0) {
      global $mydb;
        $attributes = $this->sanitized_attributes();
        $attribute_pairs = array();
        foreach($attributes as $key => $value) {
          $attribute_pairs[] = "{$key}='{$value}'";
        }
        $sql = "UPDATE ".self::$tblname." SET ";
        $sql .= join(", ", $attribute_pairs);
        $sql .= " WHERE ID=". $id;
      $mydb->setQuery($sql);
        if(!$mydb->executeQuery()) return false;    
        
    }

    public function delete($id=0) {
        global $mydb;
          $sql = "DELETE FROM ".self::$tblname;
          $sql .= " WHERE StudentID=". $id;
          $sql .= " LIMIT 1 ";
          $mydb->setQuery($sql);
          
            if(!$mydb->executeQuery()) return false;    
    
    }   


}


source https://stackoverflow.com/questions/70550599/good-day-im-trying-to-make-a-student-log-in-form-using-php-and-xampp-to-run-the

Comments

Popular posts from this blog

Prop `className` did not match in next js app

I have written a sample code ( Github Link here ). this is a simple next js app, but giving me error when I refresh the page. This seems to be the common problem and I tried the fix provided in the internet but does not seem to fix my issue. The error is Warning: Prop className did not match. Server: "MuiBox-root MuiBox-root-1" Client: "MuiBox-root MuiBox-root-2". Did changes for _document.js, modified _app.js as mentioned in official website and solutions in stackoverflow. but nothing seems to work. Could someone take a look and help me whats wrong with the code? Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console