Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Biblioteca PHP

Estas en el tema de Biblioteca PHP en el foro de PHP en Foros del Web. IngresarAdministrador.php Código PHP: <?php session_start ();      if (isset( $_POST [ "usuario" ]))     {      if (isset( $_POST [ "usuario" ])== "Administrador"  && ( $_POST [ "clave" ]== "123" ...
  #1 (permalink)  
Antiguo 29/10/2013, 06:32
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Biblioteca PHP

IngresarAdministrador.php

Código PHP:
<?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("img/4.jpg");
  }
 #registros
  {
  width:640px;
  height:640px;
  padding-top:20px;
  background-position:center;
  border-radius:20px;
  background-image:url("img/7.jpg");
  }
 #datos
  {
  width:600px;
  height:auto;
  float:center;
  background-image:url("img/2.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/23.jpg" 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>
InterfazLibro.php

Código PHP:
<?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:#CB8B8B;
   height:110px;
   width:50px;
   }
</style>
</head>
<body>
 <form action="InterfazLibros.php" method="post">
  <div id="cara"><center><img src="img/23" 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();
     }
?>
Deberia iniciar sesion en el primero para luego redirigir en el segundo pero en vez de eso se va IngresarAdministrador.php y muestra como si no lo consiguiera.
  #2 (permalink)  
Antiguo 29/10/2013, 06:42
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Porque el "action" del formulario apunta a interfazlibros y la validacion la haces en ingresoadmin
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #3 (permalink)  
Antiguo 29/10/2013, 07:00
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Listo pero no se redirige a InterfazLibro.php. El session start de IngresoAdministrador.php da error.
  #4 (permalink)  
Antiguo 29/10/2013, 07:08
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Y que error te da?
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #5 (permalink)  
Antiguo 29/10/2013, 07:13
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Bueno el de session_start era un error de llaves y ya lo resolví, asi el problema que tengo ahora es q despues de iniciar sesion debería irse a InterfazLibro.php y no lo hace...
  #6 (permalink)  
Antiguo 29/10/2013, 07:19
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Código PHP:
Ver original
  1. if(isset($_POST["usuario"])){
  2. if($_POST["usuario"]=="Administrador" && $_POST["clave"]=="123"){
  3. $_SESSION['usuario_sesion']=$_POST['usuario'];
  4. header("location:InterfazLibros.php");
  5. }
Asi deberia ser
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #7 (permalink)  
Antiguo 29/10/2013, 07:33
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Cita:
Iniciado por SkAr88 Ver Mensaje
Código PHP:
Ver original
  1. if(isset($_POST["usuario"])){
  2. if($_POST["usuario"]=="Administrador" && $_POST["clave"]=="123"){
  3. $_SESSION['usuario_sesion']=$_POST['usuario'];
  4. header("location:InterfazLibros.php");
  5. }
Asi deberia ser
Ya lo corregí, ahora lo tengo así.

Código PHP:
<?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";
      }
    }
?>
Pero no me redirige a InterfazLibro.php
  #8 (permalink)  
Antiguo 29/10/2013, 07:37
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Código PHP:
Ver original
  1. if(isset($_POST["usuario"])){
  2. if($_POST["usuario"]=="Administrador" && $_POST["clave"]=="123"){
  3. $_SESSION['usuario_sesion']=$_POST['usuario'];
  4. header("location:InterfazLibros.php");
  5. }
  6. }
Me faltaba una llave, pero fijate bien las diferencias entre lo que tu tienes y lo que puse yo
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #9 (permalink)  
Antiguo 29/10/2013, 07:48
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Cita:
Iniciado por SkAr88 Ver Mensaje
Código PHP:
Ver original
  1. if(isset($_POST["usuario"])){
  2. if($_POST["usuario"]=="Administrador" && $_POST["clave"]=="123"){
  3. $_SESSION['usuario_sesion']=$_POST['usuario'];
  4. header("location:InterfazLibros.php");
  5. }
  6. }
Me faltaba una llave, pero fijate bien las diferencias entre lo que tu tienes y lo que puse yo
Gracias, ya me redirige perfectamente. Me aparece completa InterfazLibro.php pero me salen unos errores en la parte de abajo de la pagina.

Warning: include_once(NegocioLibros.php): failed to open stream: No such file or directory in /var/www/op/InterfazLibros.php on line 72

Warning: include_once(): Failed opening 'NegocioLibros.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/op/InterfazLibros.php on line 72

Estos los otros 2 archivos del sistema.

NegociosLibros.php

Código PHP:
Ver original
  1. <?php
  2. include_once ("DatosLibros.php");
  3.  
  4. class capaNegocios
  5. {
  6.  public $codigo_libro;
  7.  public $nombre_libro;
  8.  public $descripcion_libro;
  9.  public $autor_libro;
  10.  public $categoria_libro;
  11.  public $editorial_libro;
  12.  public $cantidad_libro;
  13.  public $objetoDatos;
  14.  
  15. public function __construct($codigo_libro,$nombre_libro,$descripcion_libro,$autor_libro,$categoria_libro,$editorial_libro,$cantidad_libro)
  16.  {
  17.    $this->codigo_libro=$codigo_libro;
  18.    $this->nombre_libro=$nombre_libro;
  19.    $this->descripcion_libro=$descripcion_libro;
  20.    $this->autor_libro=$autor_libro;
  21.    $this->categoria_libro=$categoria_libro;
  22.    $this->editorial_libro=$editorial_libro;
  23.    $this->cantidad_libro=$cantidad_libro;
  24.    $this->objetoDatos=new DatosLibros ('mysql:host=localhost;dbname=b','root','hola');
  25.    }
  26.  
  27. public function insertar()
  28.  {
  29.   try
  30.     {
  31.       $this->objetoDatos->conectar();
  32.       $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')");
  33.       $this->objetoDatos->desconectar();
  34.      }
  35.   catch (PDOException $ex)
  36.      {
  37.        throw $ex;
  38.      }
  39.    }  
  40. public function eliminar()
  41.    
  42.      {
  43.       $this->objetoDatos->conectar();
  44.       $this->objetoDatos->ejecutar("delete from libros where codigo_libro=$this->codigo_libro");
  45.       $this->objetoDatos->desconectar();
  46.      }
  47.  
  48. public function modificar()
  49.      {
  50.       $this->objetoDatos->conectar();
  51.       $this->objetoDatos->ejecutar("update libros set cantidad_libro='$this->cantidad_libro' where codigo_libro=$this->codigo_libro)");
  52.       $this->objetoDatos->desconectar();
  53.      }
  54.  
  55. public function mostrar()
  56.      {
  57.       $this->objetoDatos->conectar();
  58.       $fila->$this->objetoDatos->ejecutar("select * from libros where codigo=$this->codigo");
  59.        foreach($fila as $filaActual){
  60.        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];
  61.        echo "</br>";
  62.         }
  63.       $this->objetoDatos->desconectar();
  64.      }
  65.  
  66. }
  67. ?>

DatosLibros.php

Código PHP:
Ver original
  1. <?php
  2. class DatosLibros
  3.  {
  4.   private $cadenaConexion;
  5.   private $user;
  6.   private $password;
  7.   private $objetoConexion;
  8.  
  9. public function __construct($cadenaConexion,$user,$password)
  10.      {
  11.      $this->cadenaConexion=$cadenaConexion;
  12.      $this->user=$user;
  13.      $this->password=$password;
  14.      }
  15. public function conectar ()
  16.   {
  17.    try
  18.     {
  19.      $this->objetoConexion= new PDO ($this->cadenaConexion,$this->user,$this->password);
  20.      $this->objetoConexion->setAttribute(PDO::ATTR_EARMODE,PDO::EARMODE_EXCEPTION);
  21.      }
  22.    catch (PDOException $ex)
  23.     {
  24.      echo "Se ha presentado un problema a la hora de conectar con la base de datos";
  25.      }
  26.    }
  27. public function desconectar ()
  28.     {
  29.     $this->objetoConexion=null;
  30.     }
  31. public function ejecutar ($strComando)
  32.  {
  33.   try
  34.     {
  35.      $ejecutar-> $this->objetoConexion->prepare($strComando);
  36.      $ejecutar->execute();
  37.      $rows= $ejecutar->fetchAll();
  38.      }
  39.   catch (PDOException $ex)
  40.     {  
  41.      throw $ex;
  42.      }
  43.    }
  44.   }
  45. ?>
  #10 (permalink)  
Antiguo 29/10/2013, 07:56
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

El archivo se llama Negocioslibros o Negociolibros
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #11 (permalink)  
Antiguo 29/10/2013, 07:58
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Cita:
Iniciado por SkAr88 Ver Mensaje
El archivo se llama Negocioslibros o Negociolibros
Ya lo corregí. Gracias. Disculpa la molest

Cuando le doy insertar me aparece esto
Fatal error: Function name must be a string in /var/www/op/InterfazLibros.php on line 75

Ando algo confundido con ese error ¿Alguien sabe cual es?

Última edición por GatorV; 29/10/2013 a las 09:39
  #12 (permalink)  
Antiguo 29/10/2013, 09:27
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Problema con funcion

Fatal error: Function name must be a string in /var/www/op/InterfazLibros.php on line 75

InterfazLibros.php

Código PHP:
<?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-color:$D6AF29;
  }
 #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:#CB8B8B;
   height:110px;
   width:50px;
   }
</style>
</head>
<body>
 <form action="InterfazLibros.php" method="post">
  <div id="cara"><center><img src="img/23" 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("NegociosLibros.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();
     }
?>
NegociosLibros.php

Código PHP:
<?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','');
   }

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 libros 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();
     }

}
?>
  #13 (permalink)  
Antiguo 29/10/2013, 09:34
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Problema con funcion

Estás usando $_POST() como si fuera una función, pero no lo es, es un array.

Lee el manual: http://php.net/manual/es/language.va...perglobals.php
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #14 (permalink)  
Antiguo 29/10/2013, 09:53
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Problema con funcion

Cita:
Iniciado por pateketrueke Ver Mensaje
Estás usando $_POST() como si fuera una función, pero no lo es, es un array.

Lee el manual: [url]http://php.net/manual/es/language.variables.superglobals.php[/url]
No entendí muy bien el manual. ¿Me puedes dar un ejemplo de como se diferencian las 2?
  #15 (permalink)  
Antiguo 29/10/2013, 10:04
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Biblioteca PHP

Código PHP:
Ver original
  1. // MAL
  2. $_POST('foo');
  3.  
  4. // BIEN
  5. $_POST['foo'];

¿Notas las diferencias?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #16 (permalink)  
Antiguo 29/10/2013, 10:30
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Cita:
Iniciado por pateketrueke Ver Mensaje
Código PHP:
Ver original
  1. // MAL
  2. $_POST('foo');
  3.  
  4. // BIEN
  5. $_POST['foo'];

¿Notas las diferencias?
Si. Muchas Gracias. Ahora tengo este problema:

Notice: Undefined variable: ejecutar in /var/www/op/DatosLibros.php on line 35

Notice: Trying to get property of non-object in /var/www/op/DatosLibros.php on line 35

Notice: Trying to get property of non-object in /var/www/op/DatosLibros.php on line 35

Fatal error: Call to a member function prepare() on a non-object in /var/www/op/DatosLibros.php on line 35

DatosLibros.php

Código PHP:
<?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;
     }
   }
  } 
?>
  #17 (permalink)  
Antiguo 29/10/2013, 11:25
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Biblioteca PHP

Disculpa la pregunta pero, ¿sabes programar?

Es decir, la linea que tiene el error es bastante obvia:
Código PHP:
Ver original
  1. $ejecutar-> $this->objetoConexion->prepare($strComando);

¿Estás intentando asignar algo a $ejecutar o qué pretendes?

Dicha sintaxis (la que te da el error) no podría estar mas mal, a menos que sepas lo que hace.

Código PHP:
Ver original
  1. // MAL
  2.      $ejecutar-> $this->objetoConexion->prepare($strComando);
  3.  
  4. // BIEN
  5.      $ejecutar = $this->objetoConexion->prepare($strComando);

Es increíble que no te des cuenta, ¿y encima esperas que nosotros te digamos todo lo que haces mal?

No es posible, tus errores son de sintaxis y si supieras lo que haces no los tendrías, de verdad te sugiero leer un manual.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #18 (permalink)  
Antiguo 29/10/2013, 11:34
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Lo mismo le he dicho en sus 3 o 4 temas creados con lo mismo
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.
  #19 (permalink)  
Antiguo 29/10/2013, 11:40
 
Fecha de Ingreso: octubre-2013
Mensajes: 20
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Biblioteca PHP

Muchas gracias. Apenas estoy empezando en esto. Y soy algo torpe. He estado haciendo el codigo de manera rápida y he cometido algunos errores.

Me falta este:

Fatal error: Call to a member function prepare() on a non-object in /var/www/op/DatosLibros.php on line 35
  #20 (permalink)  
Antiguo 29/10/2013, 13:16
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 1 mes
Puntos: 96
Respuesta: Biblioteca PHP

Por que no pones atencion a lo que te dice pateketrueke, creo que fue bastante explicito.
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.

Etiquetas: biblioteca, funcion, 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 19:05.