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