Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Errores en PHP

Estas en el tema de Errores en PHP en el foro de PHP en Foros del Web. Estoy haciendo un pequeño sistema bibliotecario en php pero no entiendo los errores. No se si es que hoy me levante con el cerebro torpe ...
  #1 (permalink)  
Antiguo 28/10/2013, 16:21
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 6 meses
Puntos: 0
Errores en PHP

Estoy haciendo un pequeño sistema bibliotecario en php pero no entiendo los errores. No se si es que hoy me levante con el cerebro torpe pero estoy algo atascado.
El sistema tiene 4 archivos. Aqui les va:
NegociosLibros.php
Código:
<?php
include_once ("DatosLibros.php");

class capaNegocios
{
 public $codigo_libro;
 public $nombre_libro;
 public $descripcion_libro;
 public $autor_libro;
 public $categoria_libro;
 public $editorial_libro;
 public $cantidad_libro;
 public $objetoDatos;
 } 
public function  __construct($codigo_libro,$nombre_libro,$descripcion_libro,$autor_libro,$categoria_libro,$editorial_libro,$cantidad_libro)
 {
   $this->codigo_libro=$codigo_libro;
   $this->nombre_libro=$nombre_libro;
   $this->descripcion_libro=$descripcion_libro;
   $this->autor_libro=$autor_libro;
   $this->categoria_libro=$categoria_libro;
   $this->editorial_libro=$editorial_libro;
   $this->cantidad_libro=$cantidad_libro;
   $this->objetoDatos=new DatosLibros ('mysql:host=localhost;dbname=b','root','hola');
   }

public function insertar()
  try
    {
      $this->objetoDatos->conectar();
      $this->objetoDatos->ejecutar("insert into libros(codigo_libro,nombre_libro,descripcion_libro,categoria_libro,editorial_libro,cantidad_libro) values('$this->codigo_libro','$this->nombre_libro','$this->descripcion_libro','$this->autor_libro','$this->categoria_libro','$this->editorial_libro','$this->cantidad_libro')");
      $this->objetoDatos->desconectar();
     }
  catch (PDOException $ex)
     {
       throw $ex;
     }
public function eliminar()
   
     {
      $this->objetoDatos->conectar();
      $this->objetoDatos->ejecutar("delete from libros where codigo_libro=$this->codigo_libro");
      $this->objetoDatos->desconectar();
     }

public function modificar()
     {
      $this->objetoDatos->conectar();
      $this->objetoDatos->ejecutar("update libros set cantidad_libro='$this->cantidad_libro' where codigo_libro=$this->codigo_libro)");
      $this->objetoDatos->desconectar();
     }

public function mostrar()
     {
      $this->objetoDatos->conectar();
      $fila->$this->objetoDatos->ejecutar("select * from bodega where codigo=$this->codigo");
       foreach($fila as $filaActual){
       echo "Codigo del Libro: " $filaActual [codigo_libro]"<br/>Nombre del Libro:"$filaActual [nombre_libro]"<br/>Descripcion:"$filaActual [descripcion_libro],"<br/>Autor:"$filaActual [autor_libro],"<br/>Categoria:"$filaActual [categoria_libro],"<br/>Editorial:"$filaActual [editorial_libro],"<br/>Cantidad de libros:"$filaActual [cantidad_libro];
       echo "</br>"
        }
      $this->objetoDatos->desconectar();
     }

}
?>
InterfazLibro.php
Código:
<?php
session_start();
  if ($_SESSION["usuario_sesion"] != "Administrador"){
     header("location:/IngresoAdministrador.php");
   }
?>
<html>
<head>
<title>Biblioteca</title>
<style type="text/css">
body{
 font-family:Greek Diner inline TT;
 background-image:url("img/2.jpeg");
 }
registros
{
 width:640px;
 height:640px;
 padding-top:20px;
 background-position:center;
 border-radius:20px;
 background-image:url("img/4.jpg");
 }
datos
 {
  width:600px;
  height:auto;
  float:center;
  background-image:url("img/3.jpg");
  background-position:center;
  border-radius=20px;
  }
input
  {
   border-radius:10px;
   }
input[type='submit']
  {
   background-color:$D6AF29;
   height:110px;
   width:50px;
   }
</style>
</head>
<body>
 <form action="InterfazLibros.php" method="post">
  <div id="cara"><center><img src="img/" width="850px" height="240px"/></div></br>
  <center><fieldset id="registros">
    <h1><legend>Registro</legend></h1>
    <div id="ingreso">
    <input type="text" id="codigo_libro" name="codigo_libro" placeholder="Ingrese el codigo del libro" size="30"/>
    <input type="text" id="cantidad_libro" name="cantidad_libro" placeholder="Ingrese la cantidad de libros" size="30"/>
    <input type="text" id="nombre_libro" name="nombre_libro" placeholder="Ingrese el titulo del libro" size="30"/>
    <input type="text" id="descripcion_libro" name="descripcion_libro" placeholder="Ingrese la descripcion del libro" size="30"/>
    <input type="text" id="autor_libro" name="autor_libro" placeholder="Ingrese el autor del libro" size="30"/>
    <input type="text" id="categoria_libro" name="categoria_libro" placeholder="Ingrese la categoria del libro" size="30"/>
    <input type="text" id="editorial_libro" name="editorial_libro" placeholder="Ingrese la editorial del libro" size="30"/>
    </fieldset><br/> <br/>    
  <center><fieldset id="datos">
    <legend>Botones</legend>
    <center>
    <p><input type="submit" name="insertar" id="insertar" value="Insertar"/>
    <input type="submit" name="modificar" id="modificar" value="Modificar"/>
    <input type="submit" name="eliminar" id="eliminar" value="Eliminar"/>
    <input type="submit" name="mostrar" id="mostrar" value="Mostrar"/></p>
   </fieldset > 
 </fieldset > 
</form>
</body>
</html>
<?php
include_once("NegocioLibros.php");
 try{
   if (!empty($_POST)){
     $objetoNegocio=new capaNegocios($_POST("codigo_libro"),$_POST("cantidad_libro"),$_POST("nombre_libro"),$_POST("descripcion_libro"),$_POST("autor_libro"),$_POST("categoria_libro"),$_POST("editorial_libro"));
      if (isset($_POST["insertar"])){
      $objetoNegocio->insertar();
       }
      if (isset($_POST["eliminar"])){
      $objetoNegocio->eliminar();
       }
      if (isset($_POST["modificar"])){
      $objetoNegocio->modificar();
       }
      if (isset($_POST["mostrar"])){
      $objetoNegocio->mostrar();
       }
    }
catch (PDOException $ex)
    {
     echo $ex->getMessage();
     }
?>
DatosLibros.php
Código:
<?php
class DatosLibros
 { 
  private $cadenaConexion;
  private $user;
  private $password;
  private $objetoConexion;
  }
public function  __construct($cadenaConexion,$user,$password)
     {
     $this->cadenaConexion=$cadenaConexion;
     $this->user=$user;
     $this->password=$password;
     }
public function conectar ()
  {
   try
    {
     $this->objetoConexion= new PDO ($this->cadenaConexion,$this->user,$this->password);
     $this->objetoConexion->setAttribute(PDO::ATTR_EARMODE,PDO::EARMODE_EXCEPTION);
     }
   catch (PDOException $ex)
    {
     echo "Se ha presentado un problema a la hora de conectar con la base de datos";
     }
public function desconectar
   { 
    $this->objetoConexion=null;
    }
public function ejecutar ($strComando);
 {
  try
    {
     $ejecutar-> $this->objetoConexion->prepare($strComando);
     $ejecutar->execute();
     $rows= $ejecutar->fetchAll();
     }
  catch (PDOException $ex)
    {  
     throw $ex;
     }
   }
?>
IngresoAdministrador.php
Código:
<?php
   session_start();

   if (isset($_POST["usuario"]))
     {
      if (isset($_POST["usuario"]=="Administrador") && ($_POST["clave"]=="123"))
    
      {
       $_SESSION ["usuario_sesion"]=$_SESSION ["usuario"];
       header("location:/InterfazLibros.php");
       }
      else 
      {
       echo"Error";
       }

     }

?>
<html>
<head>
<title>Biblioteca</title>
<style type="text/css">
body{
 font-family:Greek Diner inline TT;
 background-image:url();
 }
registros
{
 width:640px;
 height:640px;
 padding-top:20px;
 background-position:center;
 border-radius:20px;
 background-image:url();
 }
fdatos
 {
  width:600px;
  height:auto;
  float:center;
  background-image:url();
  background-position:center;
  border-radius=20px;
  }
input
  {
   border-radius:10px;
   }
input[type='submit']
  {
   background-color:$D6AF29;
   height:110px;
   width:50px;
   }
</style>
</head>
<body>
 <form action="InterfazLibros.php" method="post">
  <div id="cara"><center><img src="img/" width="850px" height="240px"/></div></br>
  <center><fieldset id="registros">
    <h1><legend>Iniciar Sesion</legend></h1>
    <fieldset id="datos">
    <div>
    <center>
    <input type="text" id="usuario" name="usuario" placeholder="Ingrese su nombre de usuario" size="30"/>
    </div>
    <center>
    <div>
    <input type="password" id="clave" name="clave" placeholder="Ingrese su clave" size="30"/>
    </div>
    </fieldset><br/> <br/>    
  <center><fieldset id="datos">
    <legend>Botones</legend>
    <center>
    <p><input type="submit" name="enviar" id="enviar" value="Entrar"/>
    <input type="reset" name="borrar" id="borrar" value="Borrar"/></p>
    </fieldset> 
   </fieldset> 
  </center>
</div>
</form>
</body>
</html>
Estos son los errores
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /var/www/op/DatosLibros.php on line 9.
Parse error: syntax error, unexpected '==' (T_IS_EQUAL), expecting ',' or ')' in /var/www/op/IngresoAdministrador.php on line 4
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /var/www/op/NegociosLibros.php on line 15
Parse error: syntax error, unexpected 'catch' (T_CATCH) in /var/www/op/InterfazLibros.php on line 89
  #2 (permalink)  
Antiguo 28/10/2013, 16:32
Avatar de guardarmicorreo  
Fecha de Ingreso: noviembre-2012
Ubicación: Córdoba
Mensajes: 1.153
Antigüedad: 11 años, 5 meses
Puntos: 84
Respuesta: Errores en PHP

¿qué tal si los highlight los cambias por su lenguaje correspondiente y no uno genérico para que el código quede resaltado y además aparezcan las líneas?

es muy engorroso contar 89 líneas con el puntero del ratón en el documento InterfazLibros.php por ejemplo :)

EDITO:
señala las líneas en el código, por si no correspondieran al ser pegados aquí y
también, si es posible, los string, números, etc., que estás pasando al construct y otros métodos, etc.
__________________
Ayúdame a hacerlo por mi mismo.
  #3 (permalink)  
Antiguo 28/10/2013, 16:49
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: Errores en PHP

Tienes razón aunque no se porqué no me aparece la opcion de editar.

Abri otro tema. Le pido al moderador que borre este.

Última edición por psicomago; 28/10/2013 a las 17:21
  #4 (permalink)  
Antiguo 28/10/2013, 18:23
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: Errores en PHP

En datoslibros y.negocioslibros estas cerrando la clase despues de declarar las propiedades, en ingresoadministrador estas "preguntando" si la variable.de.session esta definida pero dentro estas comparando con un string, debes usar el isset primero si retorna true comparas su valor con algo y en interfazlibros, antes del ultimo catch agrega una llave de cierre.
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.

Etiquetas: errores, html, mysql, registro, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:19.