hlmod.hu
https://hlmod.hu/

[MYSQL] Invoice System
https://hlmod.hu/viewtopic.php?f=114&t=30742
Oldal: 1 / 1

Szerző:  The Peace [ 2020.11.27. 16:12 ]
Hozzászólás témája:  [MYSQL] Invoice System

Üdv!

https://www.phpzag.com/build-invoice-system-with-php-mysql/
van ez a rendszer és nem tudná valaki hogy miért írja ki ezt a hibát? : D

Warning: mysqli::__construct(): (HY000/1049): Unknown database 'phpzag_demo' in C:\XAMPP_WEB_\htdocs\webshop\szamla\Invoice.php on line 13
Error failed to connect to MySQL: Unknown database 'phpzag_demo'


Pedig minden adat jól van ott. :D


  1. <?php
  2. class Invoice{
  3.     private $host  = '127.0.0.1';
  4.     private $user  = 'root';
  5.     private $password   = "";
  6.     private $database  = "test";  
  7.     private $invoiceUserTable = 'invoice_user';
  8.     private $invoiceOrderTable = 'invoice_order';
  9.     private $invoiceOrderItemTable = 'invoice_order_item';
  10.     private $dbConnect = false;
  11.     public function __construct(){
  12.         if(!$this->dbConnect){
  13.             $conn = new mysqli($this->host, $this->user, $this->password, $this->database);
  14.             if($conn->connect_error){
  15.                 die("Error failed to connect to MySQL: " . $conn->connect_error);
  16.             }else{
  17.                 $this->dbConnect = $conn;
  18.             }
  19.         }
  20.     }
  21.     private function getData($sqlQuery) {
  22.         $result = mysqli_query($this->dbConnect, $sqlQuery);
  23.         if(!$result){
  24.             die('Error in query: '. mysqli_error());
  25.         }
  26.         $data= array();
  27.         while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
  28.             $data[]=$row;            
  29.         }
  30.         return $data;
  31.     }
  32.     private function getNumRows($sqlQuery) {
  33.         $result = mysqli_query($this->dbConnect, $sqlQuery);
  34.         if(!$result){
  35.             die('Error in query: '. mysqli_error());
  36.         }
  37.         $numRows = mysqli_num_rows($result);
  38.         return $numRows;
  39.     }
  40.     public function loginUsers($email, $password){
  41.         $sqlQuery = "
  42.             SELECT id, email, first_name, last_name, address, mobile
  43.             FROM ".$this->invoiceUserTable."
  44.             WHERE email='".$email."' AND password='".$password."'";
  45.         return  $this->getData($sqlQuery);
  46.     }  
  47.     public function checkLoggedIn(){
  48.         if(!$_SESSION['userid']) {
  49.             header("Location:index.php");
  50.         }
  51.     }      
  52.     public function saveInvoice($POST) {       
  53.         $sqlInsert = "
  54.             INSERT INTO ".$this->invoiceOrderTable."(user_id, order_receiver_name, order_receiver_address, order_total_before_tax, order_total_tax, order_tax_per, order_total_after_tax, order_amount_paid, order_total_amount_due, note)
  55.             VALUES ('".$POST['userId']."', '".$POST['companyName']."', '".$POST['address']."', '".$POST['subTotal']."', '".$POST['taxAmount']."', '".$POST['taxRate']."', '".$POST['totalAftertax']."', '".$POST['amountPaid']."', '".$POST['amountDue']."', '".$POST['notes']."')";       
  56.         mysqli_query($this->dbConnect, $sqlInsert);
  57.         $lastInsertId = mysqli_insert_id($this->dbConnect);
  58.         for ($i = 0; $i < count($POST['productCode']); $i++) {
  59.             $sqlInsertItem = "
  60.             INSERT INTO ".$this->invoiceOrderItemTable."(order_id, item_code, item_name, order_item_quantity, order_item_price, order_item_final_amount)
  61.             VALUES ('".$lastInsertId."', '".$POST['productCode'][$i]."', '".$POST['productName'][$i]."', '".$POST['quantity'][$i]."', '".$POST['price'][$i]."', '".$POST['total'][$i]."')";        
  62.             mysqli_query($this->dbConnect, $sqlInsertItem);
  63.         }          
  64.     }  
  65.     public function updateInvoice($POST) {
  66.         if($POST['invoiceId']) {   
  67.             $sqlInsert = "
  68.                 UPDATE ".$this->invoiceOrderTable."
  69.                 SET order_receiver_name = '".$POST['companyName']."', order_receiver_address= '".$POST['address']."', order_total_before_tax = '".$POST['subTotal']."', order_total_tax = '".$POST['taxAmount']."', order_tax_per = '".$POST['taxRate']."', order_total_after_tax = '".$POST['totalAftertax']."', order_amount_paid = '".$POST['amountPaid']."', order_total_amount_due = '".$POST['amountDue']."', note = '".$POST['notes']."'
  70.                 WHERE user_id = '".$POST['userId']."' AND order_id = '".$POST['invoiceId']."'";    
  71.             mysqli_query($this->dbConnect, $sqlInsert);
  72.         }      
  73.         $this->deleteInvoiceItems($POST['invoiceId']);
  74.         for ($i = 0; $i < count($POST['productCode']); $i++) {         
  75.             $sqlInsertItem = "
  76.                 INSERT INTO ".$this->invoiceOrderItemTable."(order_id, item_code, item_name, order_item_quantity, order_item_price, order_item_final_amount)
  77.                 VALUES ('".$POST['invoiceId']."', '".$POST['productCode'][$i]."', '".$POST['productName'][$i]."', '".$POST['quantity'][$i]."', '".$POST['price'][$i]."', '".$POST['total'][$i]."')";           
  78.             mysqli_query($this->dbConnect, $sqlInsertItem);        
  79.         }          
  80.     }  
  81.     public function getInvoiceList(){
  82.         $sqlQuery = "
  83.             SELECT * FROM ".$this->invoiceOrderTable."
  84.             WHERE user_id = '".$_SESSION['userid']."'";
  85.         return  $this->getData($sqlQuery);
  86.     }  
  87.     public function getInvoice($invoiceId){
  88.         $sqlQuery = "
  89.             SELECT * FROM ".$this->invoiceOrderTable."
  90.             WHERE user_id = '".$_SESSION['userid']."' AND order_id = '$invoiceId'";
  91.         $result = mysqli_query($this->dbConnect, $sqlQuery);   
  92.         $row = mysqli_fetch_array($result, MYSQL_ASSOC);
  93.         return $row;
  94.     }  
  95.     public function getInvoiceItems($invoiceId){
  96.         $sqlQuery = "
  97.             SELECT * FROM ".$this->invoiceOrderItemTable."
  98.             WHERE order_id = '$invoiceId'";
  99.         return  $this->getData($sqlQuery); 
  100.     }
  101.     public function deleteInvoiceItems($invoiceId){
  102.         $sqlQuery = "
  103.             DELETE FROM ".$this->invoiceOrderItemTable."
  104.             WHERE order_id = '".$invoiceId."'";
  105.         mysqli_query($this->dbConnect, $sqlQuery);             
  106.     }
  107.     public function deleteInvoice($invoiceId){
  108.         $sqlQuery = "
  109.             DELETE FROM ".$this->invoiceOrderTable."
  110.             WHERE order_id = '".$invoiceId."'";
  111.         mysqli_query($this->dbConnect, $sqlQuery); 
  112.         $this->deleteInvoiceItems($invoiceId); 
  113.         return 1;
  114.     }
  115. }
  116. ?>


tábláim:

Kinyitás / összecsukásSzerkezetin voice_order
Kinyitás / összecsukásSzerkezetin voice_order_item
Kinyitás / összecsukásSzerkezetin voice_user

Szerző:  terminator100 [ 2020.11.27. 19:36 ]
Hozzászólás témája:  Re: [MYSQL] Invoice System

Üdv!

Error failed to connect to MySQL: Unknown database 'phpzag_demo' - nem írtad át az adatbázis nevet!
Vagy phpzag_demo az adatbázisneved?

Szerző:  The Peace [ 2020.11.27. 19:43 ]
Hozzászólás témája:  Re: [MYSQL] Invoice System

terminator100 írta:
Üdv!

Error failed to connect to MySQL: Unknown database 'phpzag_demo' - nem írtad át az adatbázis nevet!
Vagy phpzag_demo az adatbázisneved?


de pedig átírtam ott a funkctions.php -ban :o

TEST-re :D

netán máshol is lehetne?

UI:: URISTEN NE HARAGUDJ ÖSSZE KEVERTEM KETTŐ FUNCTIONS.PHP-t XDD <3

MOSTMÁR EZ A HIBa:(



Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in C:\XAMPP_WEB_\htdocs\webshop\szamla\Invoice.php on line 27

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in C:\XAMPP_WEB_\htdocs\webshop\szamla\Invoice.php on line 27

Szerző:  DeteCT0R [ 2020.11.28. 22:07 ]
Hozzászólás témája:  Re: [MYSQL] Invoice System

Az a "hiba" nem hiba csak figyelmeztetes hogy a kozeljovobe amikor php-verziot upgradelsz akkor lehetseges hogy tenyleges hiba lesz. (Addig figyelmen kivul hagyhatod ha nem tervezel php verziot upgradelni vagy ha csak fejlesztesz helyileg.)

Oldal: 1 / 1 Minden időpont UTC+02:00 időzóna szerinti
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/