Test Foro de elhacker.net SMF 2.1

Programación => Desarrollo Web => PHP => Mensaje iniciado por: geshiro en 19 Septiembre 2015, 00:39 AM

Título: ayuda con php orientado a objetos
Publicado por: geshiro en 19 Septiembre 2015, 00:39 AM
el problema es que al mandar llamar la funcion conectar para la conexion no porque porq dice indefinida como le haria para poder hacerla lllamar es poo en php
la que tengo que hacer llamar en la parte del table
Código (html4strict) [Seleccionar]

<?php 
include('../Models/product.php');
$product = new product();
session_start();
  if (isset(
$_SESSION['login']) && $_SESSION['login']=='YES'
  {
?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
   <title>Products</title>

   <link rel="stylesheet" href="../Resources/css/bootstrap.min.css">
   <link rel="stylesheet" href="../Resources/css/main.css">

</head>

<body>
   <!--Barra de Navegacion-->
<nav class="navbar navbar-default frm-nav">
       <div class="navbar-header">
           <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
               <span class="sr-only">Cambiar Navegacion</span>
               <span class="icon-bar"></span>
               <span class="icon-bar"></span>
               <span class="icon-bar"></span>
           </button>
           <a href="#" class="navbar-brand">Sales</a>
       </div>
       <ul class="nav navbar-nav navbar-right">
           <li class="dropdrown">
            <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['name'];?><span class="caret"></span></a>
           <ul class="dropdown-menu" role="menu">  
               <li><a href="javascript:void(0)" onclick="settings();"><span class="glyphicon glyphicon-cog"></span> Settings</a></li>
               <li><a href="javascript:void(0)" onclick="edit();"><span class="glyphicon glyphicon-edit"></span> Edit</a></li>
               <li><a href="javascript:void(0)" onclick="change();
                   "><span class="glyphicon glyphicon-repeat"></span> Change your password</a></li>
               <li class="divider"></li>
               <li><a href="javascript:void(0)" onclick="cerrar();"><span class="glyphicon glyphicon-off"> Sign out</span></a></li>
           </ul>
       </ul>  
       <ul class="nav navbar-nav navbar-right">
       <li class="dropdown">
          <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-flag"></span> Reports<span class="caret"></span></a>
         <ul class="dropdown-menu" role="menu">
           <li><a href=""><span class="glyphicon glyphicon-list"></span> Items</a></li>
           <li><a href="#"><span class="glyphicon glyphicon-list"></span> Parents list</a></li>
         </ul>
       </li>
     </ul>
     <ul class="nav navbar-nav navbar-right">
       <li><a href="javascript:void(0)" onclick=""><span class="glyphicon glyphicon-home"></span> home</a></li>
       <li><a href="javascript:void(0)" id="low_stock" onclick=""><span class="glyphicon glyphicon-alert"></span> slow stock <span id="notif" class="badge">0</span></a></li>
     </ul>
</nav>  
<div class="col-md-3">
   <ul class="nav nav-pills nav-stacked">
       <li class="active"><a href="javascript:void(0)" onclick="home();"><span class="glyphicon glyphicon-home"></span> home</a></li>
       <li><a href="javascript:void(0)" onclick="product();"><span class=" glyphicon glyphicon-bed"></span> products</a></li>
       <li><a href="javascript:void(0)" onclick="sales();"><span class="glyphicon glyphicon-credit-card"></span> Sales</a></li>
      <li><a href="javascript:void(0)" id="msg" onclick="users();"><span class="glyphicon glyphicon-user"></span> Users <span id="notif" class="badge">0</span></a></li>
   </ul>
</div>
   <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModallabel" aria-hidden="true">
                <div class="modal-dialog">
                  <div class="modal-content">
                   <div class="modal-header">
                       <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                       <h4 class="modal-title" id="myModalLabel">Registro</h4>
                   </div>
           <div class="modal-body">
               <form class="form-horizontal" id="formCliente">
                   <div class="form-group">
                       <label for="fecha" class="control-label col-xs-5">date: </label>
                       <div class="col-xs-4">
                            <input type="text" class="form-control" value="<?php echo date('y-m-d'); ?>" disabled="disabled"/>
                       </div>
                   </div>
                    <div class="form-group">
                         <label for="code" class="control-label col-xs-5">code:</label>
                         <div class="col-xs-2 frm-code">
                              <input type="text" id="code" name="code" class="form-control" onkeyup="validacion('code');" aria-describedby="inputSuccess2Status">
                              <span class="help-block"></span>
                        </div>
                  </div>
                   <div class="form-group">
                         <label for="product" class="control-label col-xs-5">Product:</label>
                         <div class="col-xs-4 frm-product">
                              <select class="form-control" id="product" name="product" onchange="validacion('product');">
                                       <option value="reset_product">Select an option</option>
                                       <option>usb 8gb</option>
                                       <option>usb 16gb  Kingston</option>
                                       <option>usb 32gb  Kingston</option>
                                       <option>usb 64gb  Kingston</option>
                                       <option>usb 128gb Kingston</option>
                                       <option>SD 8gb</option>
                                       <option>SD 16gb</option>
                                       <option>SD 32GB</option>
                                       <option>SD 64gb</option>
                                       <option>SD 128gb</option>
                                       <option>GO PRO HERO</option>
                                       <option>GO PRO BLACK EDITION</option>
                                       <option>GO PRO SILVER EDITION</option>
                                       <option>GO PRO 2 HERO</option>
                                       <option>GO PRO 2 HERO BLACK EDITION</option>
                                       <option>GO PRO 2 HERO SILVER EDITION</option>
                                       <option>GO PRO 3 HERO</option>
                                       <option>GO PRO 3 HERO</option>
                                       <option>GO PRO 3 HERO BLACK EDITION</option>
                                       <option>GO PRO 3 HERO SILVER EDITION</option>
                                       <option>Snorkel</option>
                                       <option>Aletas</option>
                                       <option>Tanque  24lb</option>
                              </select>
                        </div>
                  </div>
                    <div class="form-group">
                         <label for="price" class="control-label col-xs-5">Price:</label>
                         <div class="col-xs-3 frm-price">
                              <input type="text" class="form-control"  id="price" name="price" onkeyup="validacion('price');">
                              <span class="help-block"></span>
                        </div>
                  </div>
                    <div class="form-group">
                         <label for="stock" class="control-label col-xs-5">Stock: </label>
                         <div class="col-xs-4">
                              <select class="form-control" id="stock" name="stock" onchange="validacion('stock')";>
                                       <option value="rest_stock">Select an option</option>
                                       <option>1</option>
                                       <option>2</option>
                                       <option>3</option>
                                       <option>5</option>
                                       <option>6</option>
                                       <option>7</option>
                                       <option>8</option>
                                       <option>9</option>
                                       <option>10</option>      
                              </select>
                        </div>
                  </div>
               </form>
           </div>
           <div class="form-group">
                 <div class="alert alert-success text-center" style="display:none;" id="success">
                       <strong>Felicidades: </strong>Su registro ha sido guardado
                 </div>
                 <div class="alert alert-danger text-center" style="display:none;" id="error">
                       <strong>Alert: </strong>you must to complete all fields
                 </div>
           </div>
           <div class="modal-footer">
               <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
               <button type="button" class="btn btn-success" onclick="add_product();"><span class="glyphicon glyphicon-plus"></span> Add</button>
           </div>                
       </div>
   </div>
</div>
<div class="container">
 <div class="tab-content nav col-md-8 frm-grid">
   <h4>Products</h4>
     <div class="form-group col-xs-3 frm-search">
         <div class="form-group has-feedback">
               <input type="text" class="form-control" id="inputValidation" placeholder="Search"/>
               <span class="glyphicon glyphicon-search form-control-feedback"></span>
         </div>
   </div>
   <button class="btn btn-success frm-add" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-plus"></span> Add products</button>
   <table class="table table-hover table-resposive">
     <thead>
         <tr>
           <th>Item</th>
           <th>code</th>
           <th>Description</th>
           <th>Price</th>
           <th>Stock</th>
           <th>Actions</th>
         </tr>
     </thead>  
     <tbody>
            <?php
                  $product
->conectar();
                  
$product->show_product();
             
?>

     </tbody>
   </table>
 </div>
</div>
   <script src="../Resources/js/jquery-1.11.2.js"></script>
   <script src="../Resources/js/bootstrap.min.js"></script>
   <script src="../Resources/js/actions.js"></script>
   <script src="../Resources/js/validacion.js"></script>

   <script>
       function cerrar(){
           $.ajax({
               url:'../Controllers/user.php',
               type:'POST',
               data:"boton=cerrar"
           }).done(function(resp){
               location.href = '../Views/'
           });
       }
      function add_product(){
          var code    = $('#code').val();
          var product = $('#product').val();
          var price   = $('#price').val();
          var stock   = $('#stock').val();
          var valCheck = verificar();
            if(valCheck == 1){
             $.ajax({
                     url: '../Controllers/user.php',
                     type: 'POST',
                     data: 'code='+code+'&product='+product+'&price='+price+'&stock='+stock+'&boton=add_product'
             }).done(function(ans){
             if(ans == 'success'){
                     $('#code').val("");
                     $('#product').val('reset_product');
                     $('#price').val("");
                     $('#stock').val('rest_stock');
                     $('#success').show().delay(2000).fadeOut();
                     
             }else{
                     alert(ans);
               }
             })
           }
           else {
            }
       }
       $(function(){
           var message = $('#notif');
           $('#msg').append(message);
           message.show('slow');
       });

        $(function(){
           var message = $('#notif');
           $('#low_stock').append(message);
           message.show('slow');
       });
   </script>
</body>
</html>

<?php

  
}
  else
  {
    
header("location: ./");
  }
 
?>



Código (php-brief) [Seleccionar]

<?php
class 
product{
private $conexion;
public function __construct(){
require_once('conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}

function show_product(){
$sql "SELECT * FROM product";
$record $this->conexion->query($sql);
$item =0;

if(!$this->conexion->query($sql)){
printf("Errormessage: %s\n"$this->conexion->error);
}
if($record->num_rows>0){
while($show $record->fetch_array(MYSQLI_ASSOC)){
$item += 1;
echo '<tr>
<td>'
.$item.'</td>
<td>'
.$show["code"].'</td>
<td>'
.$show["product"].'</td>
<td>'
.$show["price"].'</td>
<td>'
.$show["stock"].'</td>
<td><button class="btn btn-warning frm-del"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"><span<button></td>
 </tr>'
;
}
}
else{
echo '<tr><td colspan="5">no hay registros</td></tr>';
}
}

}
?>



Código (php-brief) [Seleccionar]

<?php
class 
conexion
{
private $server;
private $user;
private $password;
private $database;
public  $conexion;

public function __construct(){
$this->server    "localhost";
$this->user     = "root";
$this->password  "";
$this->database  "db_login";

}

function conectar(){
$this->conexion= new mysqli($this->server,$this->user,$this->password,$this->database);
}

function cerrar(){
$this->conexion->close();
}
  
}
?>

Título: Re: ayuda con php orientado a objetos
Publicado por: T. Collins en 19 Septiembre 2015, 01:02 AM
Con esto vale:

Código (php) [Seleccionar]
<?php
       $product
->show_product();
?>


al hacer
Código (php) [Seleccionar]
<?php
       $product 
= new product();
?>


ya se inicia la conexión
Título: Re: ayuda con php orientado a objetos
Publicado por: geshiro en 19 Septiembre 2015, 01:43 AM
Osea que ponindola en el tbale $product = new product(); automatico la unicoo solo tendria que poner table ><?php $product = new product(); $product->show_product(); ?> si no para que unicie la conexion y lo muestre no?
Título: Re: ayuda con php orientado a objetos
Publicado por: T. Collins en 19 Septiembre 2015, 01:53 AM
Sí, si te fijas, el constructor de la clase product, crea la conexión y llama al método conectar() y lo deja ya preparado para usar show_product();

Código (php) [Seleccionar]
public function __construct(){
require_once('conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}
Título: Re: ayuda con php orientado a objetos
Publicado por: geshiro en 19 Septiembre 2015, 03:57 AM
Si lo vemos de manera grafica lo deje pre-preparada como sopa instantanea solo para agregarle agua
Título: Re: ayuda con php orientado a objetos
Publicado por: geshiro en 20 Septiembre 2015, 23:02 PM
ya lo movi como me dijiste pero ahora me sale
Fatal error: Call to undefined method conexion::query() in C:\xampp\htdocs\punto\Models\product.php on line 12

Código (php-brief) [Seleccionar]

<?php
class 
product{
private $conexion;
public function __construct(){
require_once('conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}

function show_product(){
$sql "SELECT * FROM product";
$record $this->conexion->query($sql);
$item =0;

if(!$this->conexion->query($sql)){
printf("Errormessage: %s\n"$this->conexion->error);
}
if($record->num_rows>0){
while($show $record->fetch_array(MYSQLI_ASSOC)){
$item += 1;
echo '<tr>
<td>'
.$item.'</td>
<td>'
.$show["code"].'</td>
<td>'
.$show["product"].'</td>
<td>'
.$show["price"].'</td>
<td>'
.$show["stock"].'</td>
<td><button class="btn btn-warning frm-del"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"><span<button></td>
 </tr>'
;
}
}
else{
echo '<tr><td colspan="5">no hay registros</td></tr>';
}
}

}
?>


Código (php-brief) [Seleccionar]

<?php
class 
conexion
{
private $server;
private $user;
private $password;
private $database;
public  $conexion;

public function __construct(){
$this->server    "localhost";
$this->user     = "root";
$this->password  "";
$this->database  "db_login";

}

function conectar(){
$this->conexion= new mysqli($this->server,$this->user,$this->password,$this->database);
}

function cerrar(){
$this->conexion->close();
}

function show_product(){

$sql "SELECT * FROM product";
$resultado $this->conexion->query($sql);
$item 0;
if (!$this->conexion->query($sql)) {
printf("Errormessage: %s\n"$this->conexion->error);
}

if($resultado->num_rows>0){
while($show $resultado->fetch_array(MYSQLI_ASSOC)){

echo '<tr>
<td>'
.$show["id_product"].'</td>
<td>'
.$show["product"].'</td>
</tr>'
;
}
}else{
echo '<tr><td colspan="6">no hay registros...</td></tr>';
}
}
}
?>

Título: Re: ayuda con php orientado a objetos
Publicado por: T. Collins en 21 Septiembre 2015, 00:06 AM
Código (php) [Seleccionar]
$record = $this->conexion->conexion->query($sql);

Código (php) [Seleccionar]
if(!$this->conexion->conexion->query($sql)){
printf("Errormessage: %s\n", $this->conexion->conexion->error);
}
Título: Re: ayuda con php orientado a objetos
Publicado por: geshiro en 23 Septiembre 2015, 08:07 AM
que le falta o puediera hacer para que mi consulta sea dinamica cuando agrege que se muestre al mismo tiempo??

Código (html4strict) [Seleccionar]

<?php 
include('../Models/product.php');
$product = new product();
session_start();
  if (isset(
$_SESSION['login']) && $_SESSION['login']=='YES'
  {
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Products</title>

    <link rel="stylesheet" href="../Resources/css/bootstrap.min.css">
    <link rel="stylesheet" href="../Resources/css/main.css">

</head>

<body>
    <!--Barra de Navegacion-->
<nav class="navbar navbar-default frm-nav">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                <span class="sr-only">Cambiar Navegacion</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="#" class="navbar-brand">Sales</a>
        </div>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdrown">
             <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['name'];?><span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">   
                <li><a href="javascript:void(0)" onclick="settings();"><span class="glyphicon glyphicon-cog"></span> Settings</a></li>
                <li><a href="javascript:void(0)" onclick="edit();"><span class="glyphicon glyphicon-edit"></span> Edit</a></li>
                <li><a href="javascript:void(0)" onclick="change();
                    "><span class="glyphicon glyphicon-repeat"></span> Change your password</a></li>
                <li class="divider"></li>
                <li><a href="javascript:void(0)" onclick="cerrar();"><span class="glyphicon glyphicon-off"> Sign out</span></a></li>
            </ul>
        </ul>   
        <ul class="nav navbar-nav navbar-right">
        <li class="dropdown">
           <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-flag"></span> Reports<span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href=""><span class="glyphicon glyphicon-list"></span> Items</a></li>
            <li><a href="#"><span class="glyphicon glyphicon-list"></span> Parents list</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="javascript:void(0)" onclick=""><span class="glyphicon glyphicon-home"></span> home</a></li>
        <li><a href="javascript:void(0)" id="low_stock" onclick=""><span class="glyphicon glyphicon-alert"></span> slow stock <span id="notif" class="badge">0</span></a></li>
      </ul>
</nav>   
<div class="col-md-3">
    <ul class="nav nav-pills nav-stacked">
        <li class="active"><a href="javascript:void(0)" onclick="home();"><span class="glyphicon glyphicon-home"></span> home</a></li>
        <li><a href="javascript:void(0)" onclick="product();"><span class=" glyphicon glyphicon-bed"></span> products</a></li>
        <li><a href="javascript:void(0)" onclick="sales();"><span class="glyphicon glyphicon-credit-card"></span> Sales</a></li>
       <li><a href="javascript:void(0)" id="msg" onclick="users();"><span class="glyphicon glyphicon-user"></span> Users <span id="notif" class="badge">0</span></a></li>
    </ul>
</div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModallabel" aria-hidden="true">
                 <div class="modal-dialog">
                   <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">Registro</h4>
                    </div>
            <div class="modal-body">
                <form class="form-horizontal" id="formCliente">
                    <div class="form-group">
                        <label for="fecha" class="control-label col-xs-5">date: </label>
                        <div class="col-xs-4">
                             <input type="text" class="form-control" value="<?php echo date('y-m-d'); ?>" disabled="disabled"/>
                        </div>
                    </div>
                     <div class="form-group">
                          <label for="code" class="control-label col-xs-5">code:</label>
                          <div class="col-xs-2 frm-code">
                               <input type="text" id="code" name="code" class="form-control" onkeyup="validacion('code');" aria-describedby="inputSuccess2Status">
                               <span class="help-block"></span>
                         </div>
                   </div>
                    <div class="form-group">
                          <label for="product" class="control-label col-xs-5">Product:</label>
                          <div class="col-xs-4 frm-product">
                               <select class="form-control" id="product" name="product" onchange="validacion('product');">
                                        <option value="reset_product">Select an option</option>
                                        <option>usb 8gb</option>
                                        <option>usb 16gb  Kingston</option>
                                        <option>usb 32gb  Kingston</option>
                                        <option>usb 64gb  Kingston</option>
                                        <option>usb 128gb Kingston</option>
                                        <option>SD 8gb</option>
                                        <option>SD 16gb</option>
                                        <option>SD 32GB</option>
                                        <option>SD 64gb</option>
                                        <option>SD 128gb</option>
                                        <option>GO PRO HERO</option>
                                        <option>GO PRO BLACK EDITION</option>
                                        <option>GO PRO SILVER EDITION</option>
                                        <option>GO PRO 2 HERO</option>
                                        <option>GO PRO 2 HERO BLACK EDITION</option>
                                        <option>GO PRO 2 HERO SILVER EDITION</option>
                                        <option>GO PRO 3 HERO</option>
                                        <option>GO PRO 3 HERO</option>
                                        <option>GO PRO 3 HERO BLACK EDITION</option>
                                        <option>GO PRO 3 HERO SILVER EDITION</option>
                                        <option>Snorkel</option>
                                        <option>Aletas</option>
                                        <option>Tanque  24lb</option>
                               </select>
                         </div>
                   </div>
                     <div class="form-group">
                          <label for="price" class="control-label col-xs-5">Price:</label>
                          <div class="col-xs-3 frm-price">
                               <input type="text" class="form-control"  id="price" name="price" onkeyup="validacion('price');">
                               <span class="help-block"></span>
                         </div>
                   </div>
                     <div class="form-group">
                          <label for="stock" class="control-label col-xs-5">Stock: </label>
                          <div class="col-xs-4">
                               <select class="form-control" id="stock" name="stock" onchange="validacion('stock')";>
                                        <option value="rest_stock">Select an option</option>
                                        <option>1</option>
                                        <option>2</option>
                                        <option>3</option>
                                        <option>5</option>
                                        <option>6</option>
                                        <option>7</option>
                                        <option>8</option>
                                        <option>9</option>
                                        <option>10</option>       
                               </select>
                         </div>
                   </div>
                </form>
            </div>
            <div class="form-group">
                  <div class="alert alert-success text-center" style="display:none;" id="success">
                        <strong>Felicidades: </strong>Su registro ha sido guardado
                  </div>
                  <div class="alert alert-danger text-center" style="display:none;" id="error">
                        <strong>Alert: </strong>you must to complete all fields
                  </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
                <button type="button" class="btn btn-success" onclick="add_product();"><span class="glyphicon glyphicon-plus"></span> Add</button>
            </div>               
        </div>
    </div>
</div>
<div class="container">
  <div class="tab-content nav col-md-8 frm-grid">
    <h4>Products</h4>
      <div class="form-group col-xs-3 frm-search">
          <div class="form-group has-feedback">
                <input type="text" class="form-control" id="inputValidation" placeholder="Search"/>
                <span class="glyphicon glyphicon-search form-control-feedback"></span>
          </div>
    </div>
    <button class="btn btn-success frm-add" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-plus"></span> Add products</button>
    <table class="table table-hover table-resposive">
      <thead>
          <tr>
            <th>Item</th>
            <th>code</th>
            <th>Description</th>
            <th>Price</th>
            <th>Stock</th>
            <th>Actions</th>
          </tr>
      </thead> 
      <tbody>
             <?php
                  $product
->show_product();
             
?>

      </tbody>
    </table>
  </div>
</div>
    <script src="../Resources/js/jquery-1.11.2.js"></script>
    <script src="../Resources/js/bootstrap.min.js"></script>
    <script src="../Resources/js/actions.js"></script>
    <script src="../Resources/js/validacion.js"></script>

    <script>
        function cerrar(){
            $.ajax({
                url:'../Controllers/user.php',
                type:'POST',
                data:"boton=cerrar"
            }).done(function(resp){
                location.href = '../Views/'
            });
        }
       function add_product(){
           var code    = $('#code').val();
           var product = $('#product').val();
           var price   = $('#price').val();
           var stock   = $('#stock').val();
           var valCheck = verificar();
             if(valCheck == 1){
              $.ajax({
                      url: '../Controllers/actions.php',
                      type: 'POST',
                      data: 'code='+code+'&product='+product+'&price='+price+'&stock='+stock+'&boton=add_product'
              }).done(function(ans){
              if(ans == 'success'){
                      $('#code').val("");
                      $('#product').val('reset_product');
                      $('#price').val("");
                      $('#stock').val('rest_stock');
                      $('#success').show().delay(2000).fadeOut();

              }else{
                      alert(ans);
                }
              })
            }
            else {
             }
        }
        $(function(){
            var message = $('#notif');
            $('#msg').append(message);
            message.show('slow');
        });

         $(function(){
            var message = $('#notif');
            $('#low_stock').append(message);
            message.show('slow');
        });
    </script>
</body>
</html>

<?php
 
  
}
  else
  {
    
header("location: ./");
  }
 
?>



Código (php-brief) [Seleccionar]

<?php
class 
product{
private $conexion;
public function __construct(){
require_once('conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}

function add($price,$stock,$code,$product){
$sql1 ="INSERT INTO product (price,stock,code,product) VALUES('$price','$stock','$code','$product')";
if($this->conexion->conexion->query($sql1)){
return true;
}
else{
return false;
}
$this->conexion->cerrar();
}
 
function show_product(){
$sql "SELECT * FROM product";
$record $this->conexion->conexion->query($sql);
$item =0;
 
if(!$this->conexion->conexion->query($sql)){
printf("Errormessage: %s\n"$this->conexion->conexion->error);
}
if($record->num_rows>0){
while($show $record->fetch_array(MYSQLI_ASSOC)){
$item += 1;
echo '<tr>
<td>'
.$item.'</td>
<td>'
.$show["code"].'</td>
<td>'
.$show["product"].'</td>
<td>'
.$show["price"].'</td>
<td>'
.$show["stock"].'</td>
<td><button class="btn btn-warning frm-del"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"><span<button></td>
 </tr>'
;
}
}
else{
echo '<tr><td colspan="5">no hay registros</td></tr>';
}
}
 
}
?>