Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/06/2013, 09:06
Avatar de guardarmicorreo
guardarmicorreo
 
Fecha de Ingreso: noviembre-2012
Ubicación: Córdoba
Mensajes: 1.153
Antigüedad: 12 años, 5 meses
Puntos: 84
Respuesta: Problema con aplicación web

Cita:
Iniciado por salva_bxt Ver Mensaje
Pues he estado creando un sistema mediante el cual se puedan crear categorias, y articulos, dichas categorias y articulos se muestren y tal (lo normal)
La cosa es que esa parte es fácil, pero tamién quería crear un archivo mediante el cual pueda administrar las cateorias (y otro los articulos), sin embargo, consigo seleccionar las categorias y mostrarlas en localhost, pero no en mi sitio web
Tampoco consigo ni en localhost ni en mi sitio web. hacer para "editarlas", y a eliminarlas por ejemplo, ni he llegado XD

El código del archivo que gestiona las categorias es este
Código PHP:
Ver original
  1. <html>
  2. <head>
  3.     <link href="/onfire/css/bootstrap.css" rel="stylesheet">
  4.         <style type="text/css">
  5.       body {
  6.         padding-top: 60px;
  7.         padding-bottom: 40px;
  8.       }
  9.       .sidebar-nav {
  10.         padding: 9px 0;
  11.       }
  12.  
  13.       @media (max-width: 980px) {
  14.         /* Enable use of floated navbar text */
  15.         .navbar-text.pull-right {
  16.           float: none;
  17.           padding-left: 5px;
  18.           padding-right: 5px;
  19.         }
  20.       }
  21.     </style>
  22. </head>    
  23. <body>
  24.  
  25. <?php
  26.     include ('/../config.php');
  27.     include ('/../functions.php');
  28.  
  29. if (!isset($_GET['action']))
  30. {
  31. //If not isset -> set with dumy value
  32. $_GET['action'] = "view";
  33. }    
  34.        
  35.         $action =  $_GET['action'];
  36.  
  37.        
  38.         switch($action)
  39.         {
  40.             case 'view':
  41.      ?>          
  42.                 <table class="table table-striped">
  43.   <thead>
  44.     <tr>
  45.       <th>ID</th>
  46.       <th>Name</th>
  47.       <th>Type</th>
  48.       <th>Status</th>
  49.     </tr>
  50.   </thead>
  51.   <tbody>
  52.   <?php
  53.   error_reporting(E_ALL ^ E_NOTICE);
  54.     $sql = "SELECT * from category";
  55.     $result = mysqli_query($con, $sql);
  56.   while($row = mysqli_fetch_array($result)){
  57.     echo '
  58.    <tr>
  59.      <td> '.$row["id"].'</td>
  60.      <td> '.$row["name"].'</td>
  61.      <td> '.$row["type"].' </td>
  62.      <td> '.$row["status"].' </td>
  63.      <td><a href="category.php?action=edit&id='.$row["id"].'"><button class="btn btn-mini btn-success" type="button">Editar</button></a></td>
  64.      <td><a href="category.php?action=delete&id='.$row["id"].'"><button class="btn btn-mini btn-danger" type="button">Eliminar</button></a></td>
  65.    </tr>';
  66. } ?>
  67.   </tbody>
  68. </table>
  69.                 <a href="category.php?action=add"><button class="btn btn-mini btn-info" type="button">Añadir</button></a>
  70. <?php
  71.                
  72.                 break;
  73.            
  74.             case 'add':
  75.                
  76.                 ?>
  77. <form method="post" action="category.php?action=add&add=cat">
  78. Nombre: <input type="text" class="input-medium" name="name" placeholder="Nombre de la categoria" /> <br/><br/>
  79. Tipo: <input type="text" class="input-large" name="type" placeholder="Tipo de articulo (0 o 1)"/> <br /><br/>
  80. Estado: <input type="text" class="input-large" name="status" placeholder="Tipo de categoria (0 o 1)"/> <br /><br/>
  81. <input type="submit" value="Enviar" class="btn" />
  82. </form>
  83.                
  84.                 <?php
  85.                 error_reporting(E_ALL ^ E_NOTICE);
  86.                 if ($_GET["add"] == "cat"){
  87.                     $name = $_POST['name'];
  88.                     $type = $_POST['type'];
  89.                     $status = $_POST['status'];
  90.  
  91.                     $sql = "INSERT INTO `category` (`name`,`type`,`status`)  VALUES ('$name','$type','$status');";
  92.                     $result = mysqli_query($con, $sql);
  93.                    
  94.                     if ($result){
  95.                         echo 'Categoria creada con éxito, haz <a href="category.php?action=view">clic aqui</a> para volver atrás ';
  96.                        
  97.                     }
  98.                 }
  99.                
  100.                 break;
  101.            
  102.            
  103.             case 'edit':
  104.                   error_reporting(E_ALL ^ E_NOTICE);
  105.                   $id = $_GET['id'];
  106.  
  107.                 $sql = "SELECT * from category WHERE id='".$id."' ";
  108.                 $result = mysqli_query ($con, $sql) or die (mysqli_error()) ;
  109.                while($row = mysql_fetch_array($result)){
  110. $rowid = $row['id'];
  111. $name = $row['name'];
  112. $status = $row['status'];
  113. $type = $row['type'];
  114.  
  115. echo '<form method="post" action="category.php?action=update&mode=edit">
  116. <input type="hidden" name="id" value="$id" />
  117. Nombre: <input type="text" class="input-medium" name="name" value="$name" /> <br/><br/>
  118. Tipo: <input type="text" class="input-large" name="type" value="$type"/> <br /><br/>
  119. Estado: <input type="text" class="input-large" name="status" value="$status"/> <br /><br/>
  120. <input type="submit" value="Enviar" class="btn" />
  121. </form>';
  122.                }
  123.                 break;
  124.            
  125.             case 'delete':
  126.                
  127.                 echo $action;
  128.                
  129.                 break;
  130.            
  131.             case 'update':
  132.                
  133.                 echo $action;
  134.                
  135.                 break;
  136.            
  137.            
  138.         }
  139.        
  140.        
  141.        
  142. ?>
  143.  
  144.  
  145. </body>
  146. </html>
Me muestra los siguientes errores
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given
Warning: mysqli_error() expects exactly 1 parameter, 0 given

Mientras que en localhost, en el edit me da este error
Warning: mysql_fetch_array() expects parameter 1 to be resource, object given

¿Que sucede, algun consejo, etc?

PD: El config.php esta en otro directorio, y este hecho de forma en q pasa por la variable $con todos los par
la variable $con, que es la que supongo tendrá las credenciales de autenticación para conectarte a la base de datos ¿cómo la obtienes en este documento?

porque la tienes en otro documento que incluyes, pero no veo que en este documento instancias a una clase o declares dicha variable.

es lo que he visto en la primera consulta, ya que los errores que muestras son porque les falta un parámetro que recibir, sospecho que es $con