Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola, que estou tentando fazer um sistema de agenda (de uma video aula), mas não estou conseguindo inserir registros.
vou postar os codigos, se alguem puder me dar uma luz xD
config.php:
<?
define('SMARTY_DIR','lib/Smarty/libs/');
include(SMARTY_DIR.'Smarty.class.php');
include 'lib/cursophp/bd.php';
include 'lib/cursophp/agenda.php';
$smarty = new Smarty();
$smarty->cache_dir = "cache";
$smarty->config_dir = "configs";
$smarty->compile_dir = "templates_c";
$smarty->template_dir = "templates";
$bd = new Bd('localhost','root','','php_agenda');
$bd->connect();
$agenda = new Agenda($bd,'agenda');
?>
db.php:
<?php
class BD {
/ Atributos /
protected $_host;
protected $_user;
protected $_senha;
protected $_bd;
/* Construtor */
public function __construct($host,$user,$senha,$bd){
$this->_host = $host;
$this->_user = $user;
$this->_senha = $senha;
$this->_bd = $bd;
}
/* Gets */
public function getHost(){
return $this->_host;
}
public function getUser(){
return $this->_user;
}
public function getBd(){
return $this->_bd;
}
/* Sets */
/* Conecções */
public function connect(){
mysql_connect($this->_host,$this->_user,$this->_senha);
mysql_select_db($this->_bd);
}
public function select ($colunas,$tabela){
$sql = "select $colunas from $tabela";
$res = mysql_query($sql);
$ret = array();
if(mysql_num_rows($res)>0){
for($i=0;$i<mysql_numrows($res);$i++){
$ret[] = mysql_fetch_array($res);
}
}
return $ret;
}
public function remover($tabela,$id) {
$sql = "delete from agenda where id='$id'";
mysql_query($sql);
}
public function insert($tabela,$campos,$valores){
$slq = "Insert into `$tabela` ($campos) Values($valores)";
mysql_query($sql);
}
}
?>
agenda.php:
<?php
class Agenda {
protected $_bd;
public $_tabela;
public function __construct(Bd $bd, $tabela){
$this->_bd = $bd;
$this->_tabela = $tabela;
}
public function listar(){
return $this->_bd->select('*',$this->_tabela);
}
public function remover(){
$this->_bd->remover($this->_tabela,$id);
}
public function insert($nome,$sobrenome,$email,$telefone,$celular) {
$campos = "nome,sobrenome,email,telefone,celular";
$valores = "'$nome','$sobrenome','$email','$telefone','$celular'";
$this->_bd->insert($this->tabela,$campos,$valores);
}
}
?>
edit.php:
<?
include 'config.php';
include 'funcoes.php';
if(!isset($_REQUEST['edit']))
$_REQUEST['edit'] = 0;
$smarty->assign('edit',$_REQUEST['edit']);
if($_REQUEST['edit']>0) {
$dados = get($_REQUEST['edit']);
$smarty->assign('dados',$dados);
}
if (isset($_REQUEST ['submit'] )){
if($_REQUEST['edit']==0) {
$agenda->insert( $_REQUEST['nome'],$_REQUEST['sobrenome'],$_REQUEST['email'],$_REQUEST['telefone'],$_REQUEST['celular']);
}
else{
alterar ( $_REQUEST['edit'],$_REQUEST['nome'],$_REQUEST['sobrenome'],$_REQUEST['email'],$_REQUEST['telefone'],$_REQUEST['celular']);
}
$smarty->assign ( 'sucesso','1' );
}
$smarty->assign('mid', 'edit.tpl');
$smarty->display('layout.tpl');
?>
espero q não esteja muito confuso @.@, se alguem puder me ajudar xD
Carregando comentários...