Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Niel Rocha

Criando um sistema bibliotecario

Recommended Posts

Olá pessoal sou novo na linguagem PHP tenho um problema aqui e espero que alguém aqui me ajude por favor é para estudo de faculdade, é um sistema de uma biblioteca em php, onde o aluno vai pegar o livro emprestado e daí onde na página de cadastro do livro "tal" vai ter um local para inserir a quantidade "X" daí quando o aluno for pegar emprestado ele vai fazer uma decrementação no estoque (ou estante de livro) e quando devolver incrementar para que quando não houver mais livro na estante ,ou seja,(estoque) aprarecer uma mensagem dizendo que não há o livro! postei o código SQL se alguém se tiver errado as relações de chaves me avisem, também, Na tela que listar o livro vai mostrar a quantidade em estoque de já fico muito grato, pois sei que aqui é o melhor lugar para compartilhar conhecimentoss valew

-- phpMyAdmin SQL Dump
-- version 4.1.14
--
-- Host: 127.0.0.1
-- Generation Time: 26-Ago-2016 às 18:46
-- Versão do servidor: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `biblioooo`
--
-- --------------------------------------------------------
--
-- Estrutura da tabela `aluno`
--
CREATE TABLE IF NOT EXISTS `aluno` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`matricula` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`curso` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`data_ingresso` timestamp NOT NULL,
`data_nascimento` timestamp NOT NULL,
`sexo` tinyint(11) NOT NULL,
`endereco` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`is_active` tinyint(1) NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Estrutura da tabela `emprestimo`
--
CREATE TABLE IF NOT EXISTS `emprestimo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ejemplar_id` int(11) NOT NULL,
`aluno_id` int(11) NOT NULL,
`created_at` date NOT NULL,
`return_at` date NOT NULL,
`returned_at` date NOT NULL,
`prestador_id``` int(11) NOT NULL,
`receptor_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `aluno_id` (`aluno_id`),
KEY `ejemplar_id` (`ejemplar_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Estrutura da tabela `livro`
--
CREATE TABLE IF NOT EXISTS `livro` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`titulo` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`autor` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`edicao` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`editora` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`quan_stoque` int(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Constraints for dumped tables
--
--
-- Limitadores para a tabela `emprestimo`
--
ALTER TABLE `emprestimo`
ADD CONSTRAINT `aluno` FOREIGN KEY (`aluno_id`) REFERENCES `aluno` (`id`),
ADD CONSTRAINT `emjemplar` FOREIGN KEY (`ejemplar_id`) REFERENCES `livro` (`id`);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigo, como o Maykel falou, a galera não vai fazer o seu trabalho da faculdade, pois o intuito la e aqui deve ser aprender, se você não saber por onde começar, começa pelo algoritmo da sua aplicação, depois divida o trabalho em etapas e posta as duvidas aqui, mas não peça códigos feitos.

vlw :)

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ta beleza tinha que pô os códigos aqui mesmo e a dúvida depois coloco o mais códigos

protected $sqlAtualizar = "UPDATE aluno set nome='%s', "
//essa é a linha 29>>>>>> . "mastricula='%s', sexo='%s', email='%s',curso='%s',endereco='%s',data_ingresso='%s',data_nascimento='%s' "
. "WHERE id_aluno = '%s'";
esse é a sintaxe do erro
Parse error: syntax error, unexpected '.', expecting ',' or ';' in C:\wamp\www\TrabBlioteca\model\mAluno.php on line 29
alguém pod me ajudar aqui por favor!

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php require 'model/config.php';


/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/


/**

* Description of contatosDAO

*

* @author Daniel

*/

class mAluno extends config{

//put your code here

private $id_aluno;

private $matricula;

private $nome;

private $sexo;

private $email;

private $curso;

private $endereco;

private $data_ingresso;

private $data_nascimento;


//criando váriaveis de manipulação no banco

protected $sqlInserir = "INSERT INTO aluno (id_aluno,nome, matricula, sexo,email,curso,endereco,data_ingresso,data_nascimento ) "

. "VALUES ('%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')";






protected $sqlAtualizar = "UPDATE aluno set nome='%s', "

. "mastricula='%s', sexo='%s', email='%s',curso='%s',endereco='%s',data_ingresso='%s',data_nascimento='%s' "

. "WHERE id_aluno = '%s'";

protected $sqlDeletar = "DELETE FROM aluno "

. "WHERE id_aluno = '%s'";

protected $sqlSelecionar = "SELECT * FROM aluno WHERE 1=1 %s %s";


//________________________________________________

public function setId_aluno($id_aluno) {

$this->id_aluno = $id_aluno;

}


public function getId_aluno() {

return $this->id_aluno;

}

//_______________________________________________________

public function setNome($nome) {

$this->nome = $nome;

}


public function getNome() {

return $this->nome;

}

//_________________________________________________________

public function setEmail($email) {

$this->email = $email;

}


public function getEmail() {

return $this->email;

}

//_______________________________________________________________

public function setCurso($curso) {

$this->curso = $curso;

}


public function getCurso() {

return $this->curso;

}

//____________________________________________________________


public function setEndereco($endereco) {

$this->endereco = $endereco;

}


public function getEndereco() {

return $this->endereco;

}

//_________________________________________________________________


public function setMatricula($matricula) {

$this->matricula = $matricula;

}


public function getMatricula() {

return $this->matricula;

}

//_________________________________________________________________


public function setSexo($sexo) {

$this->sexo = $sexo;

}


public function getSexo() {

return $this->sexo;

}

//_________________________________________________________________


public function setData_ingresso($data_ingresso) {

$this->data_ingresso = $data_ingresso;

}


public function getData_ingresso() {

return $this->data_ingresso;

}

//_________________________________________________________________


public function setData_nascimento($data_nascimento) {

$this->data_nascimento = $data_nascimento;

}


public function getData_nascimento() {

return $this->data_nascimenro;

}

//_________________________________________________________________




//função para inserir os valores

public function inserir(){

//preenche valores de dados

$sql = sprintf($this->sqlInserir,

$this->getNome(), $this->getMatricula(),

$this->getEmail(), $this->getCurso(),

$this->getEndereco(), $this->getData_ingresso(),

$this->getSexo(), $this->getData_nascimento());


return $this->RodaQuery($sql);

}


public function atualizar() {

//preenche dados a serem atualizados

$sql = sprintf($this->sqlAtualizar, $this->getNome(), $this->getMatricula(),

$this->getEmail(), $this->getCurso(),$this->getId_aluno(),

$this->getEndereco(), $this->getData_ingresso(),

$this->getSexo(), $this->getData_nascimento());



echo $sql;

return $this->RodaQuery($sql);


}


public function deletar() {

//preenche dados a serem atualizados

$sql = sprintf($this->sqlDeletar, $this->getId_aluno());

return $this->RodaQuery($sql);


}


public function selecionar($where='',$order='') {

//preenche dados a serem atualizados

$sql = sprintf($this->sqlSelecionar, $where, $order);

return $this->RodaSelect($sql);


}


public function carregar() {

//preenche dados a serem atualizados

$rs = $this->selecionar(sprintf("and id_aluno = '%s'", $this->getId_aluno()));

$this->setId_aluno($rs[0]['id_aluno']);

$this->setNome($rs[0]['nome']);

$this->setEmail($rs[0]['email']);

$this->setMatricula($rs[0]['matricula']);

$this->setSexo($rs[0]['sexo']);

$this->setCurso($rs[0]['curso']);

$this->setEndereco($rs[0]['endereco']);

$this->setData_ingresso($rs[0]['data_ingresso']);

$this->setData_nascimento($rs[0]['data_nascimento']);



return $this;


}

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Primeira vez em mais de uma década de estudos, que vi uma template de SQL declarada nos atributos de uma classe.


Cria uma query "Update" para baixar o estoque, o que ta faltando para você é entender o conceito de CRUD. Não vou nem comentar se você conhece ou não OOP.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Na linha onde devia ter "matricula" está "mastricula" veja isso.

Como você é novo na linguagem, aconselharia a tentar trabalhar com algo menos complexo e um codigo comentado, sinceramente não entendi nada dessa classe.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.