Ir para conteúdo

Arquivado

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

Fabyo

Sistema de Cadastro em PHP/MySQL

Recommended Posts

Caro Fabyo, eu tenho um exemplo aqui sobre o que você falou, mas nunca funcionou. Quando eu clico no enviar para inserir um registro a pagina fica em branco e ele nao insere.

 

É um bom exemplo onde você tem o insert, update e delete num so arquivo, veja se ficaria bacana incorporar no seu exemplo.

 

Se voce conseguir identificar o erro do porquê não funcionar, eu te agradeço.

 

==================

 

 

Segue o arquivo de nome set.php

//função incluir clientes
if ($acao=='incluir') {

$ac=mysql_query("insert into clientes(
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10,
c11, c12, c13, c14, c15, c16, c17, c18, c19,
c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30)

		  values
		  
('$c1','$c2','$c3','$c4','$c5','$c6','$c7','$c8','$c9','$c10',
'$c11','$c12','$c13','$c14','$c15','$c16','$c17','$c18','$c19','$c20',
'$c21','$c22','$c23','$c24','$c25','$c26','$c27','$c28','$c29','$c30')")

							 or die (mysql_error());
							 
							 echo"<script language=javascript>alert('Operação efetuada com sucesso!')</script>";
							 echo"<script language=javascript>location.href='incluir.php'</script>";
							 
							 mysql_close();
							 // fim da função incluir

							 }

//função alterar clientes
if ($acao=='up') {

$ac=mysql_query
("update clientes set
c1= '$c1 ',
c3= '$c3 ',
c4= '$c4 ',
c5= '$c5 ',
c6= '$c6 ',
c7= '$c7 ',
c8= '$c8 ',
c9= '$c9 ',
c10='$c10',
c11='$c11',
c12='$c12',
c13='$c13',
c14='$c14',
c15='$c15',
c16='$c16',
c17='$c17',
c18='$c18',
c19='$c19',
c20='$c20',
c21='$c21',
c22='$c22',
c23='$c23',
c24='$c24',
c25='$c25',
c26='$c26',
c27='$c27',
c28='$c28',
c29='$c29',
c30='$c30'
where cliente='$cliente'") or die (mysql_error());

							 echo"<script language=javascript>alert('Operação efetuada com sucesso!')</script>";
							 echo"<script language=javascript>location.href='listar.php'</script>";

							   mysql_close();	 }
							   //fim da função alterar
							   
//função remover
if ($acao=='del') {

$ac=mysql_query("delete from clientes where cliente='$cliente'") or die (mysql_error());

							 echo"<script language=javascript>alert('Operação efetuada com sucesso!')</script>";
							 echo"<script language=javascript>location.href='listar.php'</script>";
							 
								mysql_close();	}
								//fim da função remover


?>
========

 

Abs e obrigado!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Fabyo, primeiramente muito obrigado pelo Sistema! ^^

 

Eu modifiquei ele, mas só que estou com problemas na hora de Editar um cadastro.

 

Você pode verificar por aqui: http://micaelborin.com/sistema/editar.php?id=4 , aparece a mensagem: <br /> <b>Notice</b>: Undefined variable: nome in <b>/home/micael/public_html/sistema/editar.php</b> on line <b>39</b><br /> dentro dos Campos.

 

Você poderia me ajudar?

 

Segue abaixo o meu: editar.php

 

<?php
if(file_exists("init.php")) {
	require "init.php";		
} else {
	echo "Arquivo init.php nao foi encontrado";
	exit;
}

if(!function_exists("Abre_Conexao")) {
	echo "Erro o arquivo init.php foi auterado, nao existe a função Abre_Conexao";
	exit;
}

$id = $_GET["id"];

Abre_Conexao();
$re	= mysql_query("select count(*) as total from cadastro where id_usuario = $id");	
$total = mysql_result($re, 0, "total");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>
<style>
<!--
.textBox { border:1px solid gray; width:200px;} 
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="salvar_edicao.php">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
  <table width="400" border="0" align="center">
	<tr>
	  <td width="145">Nome</td>
	  <td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" value="<?php echo $nome["nome"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Versão</td>
	  <td><input name="versao" type="text" id="versao" maxlength="64" class="textBox" value="<?php echo $dados["versao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Configuravel</td>
	  <td><input name="configuravel" type="radio" value="S" <?php echo $dados["configuravel"] == "S" ? "checked=\"checked\"" : ""; ?> /><label>Sim</label> 
	  <input name="configuravel" type="radio" value="N" <?php echo $dados["configuravel"] == "N" ? "checked=\"checked\"" : ""; ?> /> <label>Não</label></td>
	</tr>
	<tr>
	  <td>Descrição</td>
	  <td><input name="descricao" type="text" id="descricao" maxlength="30" class="textBox" value="<?php echo $dados["descricao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Tradução - Pt-br</td>
	  <td><input name="traducao_ptbr" type="text" id="traducao_ptbr" maxlength="30" class="textBox" value="<?php echo $dados["traducao_ptbr"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Dificuldade</td>
	  <td><input name="dificuldade" type="text" id="dificuldade" maxlength="20" class="textBox" value="<?php echo $dados["dificuldade"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Tempo</td>
	  <td><input name="tempo" type="text" id="tempo" maxlength="45" class="textBox" value="<?php echo $dados["tempo"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Português</td>
	  <td><input name="disc_pt" type="text" id="disc_pt" maxlength="40" class="textBox" value="<?php echo $dados["disc_pt"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Inglês</td>
	  <td><input name="disc_en" type="text" id="disc_en" maxlength="10" class="textBox" value="<?php echo $dados["disc_en"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Download</td>
	  <td><input name="download" type="text" id="download" maxlength="10" class="textBox" value="<?php echo $dados["download"]; ?>"/></td>
	</tr>
	<tr>
	  <td> </td>
	  <td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>
	</tr>
  </table>
</form>
</body>
</html>

Obrigado,

Micael

Compartilhar este post


Link para o post
Compartilhar em outros sites

Fabyo, muito obrigado pela atenção.

 

Modifiquei o Arquivo, mas mesmo assim na hora de Editar aparece as mensagens:

http://micaelborin.com/sistema/editar.php?id=6

 

 

Segue o meu editar.php depois da modificação:

 

<?php
if(file_exists("init.php")) {
	require "init.php";		
} else {
	echo "Arquivo init.php nao foi encontrado";
	exit;
}

if(!function_exists("Abre_Conexao")) {
	echo "Erro o arquivo init.php foi auterado, nao existe a função Abre_Conexao";
	exit;
}

$id = $_GET["id"];

Abre_Conexao();
$re	= mysql_query("select count(*) as total from cadastro where id_usuario = $id");	
$total = mysql_result($re, 0, "total");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>
<style>
<!--
.textBox { border:1px solid gray; width:200px;} 
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="salvar_edicao.php">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
  <table width="400" border="0" align="center">
	<tr>
	  <td width="145">Nome</td>
	  <td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" value="<?php echo $dados["nome"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Versão</td>
	  <td><input name="versao" type="text" id="versao" maxlength="64" class="textBox" value="<?php echo $dados["versao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Configuravel</td>
	  <td><input name="configuravel" type="radio" value="S" <?php echo $dados["configuravel"] == "S" ? "checked=\"checked\"" : ""; ?> /><label>Sim</label> 
	  <input name="configuravel" type="radio" value="N" <?php echo $dados["configuravel"] == "N" ? "checked=\"checked\"" : ""; ?> /> <label>Não</label></td>
	</tr>
	<tr>
	  <td>Descrição</td>
	  <td><input name="descricao" type="text" id="descricao" maxlength="30" class="textBox" value="<?php echo $dados["descricao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Tradução - Pt-br</td>
	  <td><input name="traducao_ptbr" type="text" id="traducao_ptbr" maxlength="30" class="textBox" value="<?php echo $dados["traducao_ptbr"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Dificuldade</td>
	  <td><input name="dificuldade" type="text" id="dificuldade" maxlength="20" class="textBox" value="<?php echo $dados["dificuldade"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Tempo</td>
	  <td><input name="tempo" type="text" id="tempo" maxlength="45" class="textBox" value="<?php echo $dados["tempo"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Português</td>
	  <td><input name="disc_pt" type="text" id="disc_pt" maxlength="40" class="textBox" value="<?php echo $dados["disc_pt"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Inglês</td>
	  <td><input name="disc_en" type="text" id="disc_en" maxlength="10" class="textBox" value="<?php echo $dados["disc_en"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Download</td>
	  <td><input name="download" type="text" id="download" maxlength="10" class="textBox" value="<?php echo $dados["download"]; ?>"/></td>
	</tr>
	<tr>
	  <td> </td>
	  <td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>
	</tr>
  </table>
</form>
</body>
</html>

Obrigado pela atenção,

Micael

Compartilhar este post


Link para o post
Compartilhar em outros sites

só copiar meu ultimo editar corretamente

 

esta faltando no seu editar

 

if($total == 1) {

$re = mysql_query("select * from usuarios, estados where estados.id_estado = usuarios.fk_estado and usuarios.id_usuario = $id");

$dados = mysql_fetch_array($re);

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Fabyo, eu alterei, só que agora aparece:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/micael/public_html/sistema/editar.php on line 22

 

Lembrando que eu não tenho a o campo Estados.

 

Segue abaixo o arquivo editar.php:

 

<?php
if(file_exists("init.php")) {
	require "init.php";		
} else {
	echo "Arquivo init.php nao foi encontrado";
	exit;
}

if(!function_exists("Abre_Conexao")) {
	echo "Erro o arquivo init.php foi auterado, nao existe a função Abre_Conexao";
	exit;
}

$id = $_GET["id"];

Abre_Conexao();
$re	= mysql_query("select count(*) as total from cadastro where id_usuario = $id");	
$total = mysql_result($re, 0, "total");

if($total == 1) {
$re = mysql_query("select * from cadastro, cadastro where usuarios.id_usuario = $id");
$dados = mysql_fetch_array($re); 
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>
<style>
<!--
.textBox { border:1px solid gray; width:200px;} 
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="salvar_edicao.php">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
  <table width="400" border="0" align="center">
	<tr>
	  <td width="145">Nome</td>
	  <td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" value="<?php echo $dados["nome"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Versão</td>
	  <td><input name="versao" type="text" id="versao" maxlength="64" class="textBox" value="<?php echo $dados["versao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Configuravel</td>
	  <td><input name="configuravel" type="radio" value="S" <?php echo $dados["configuravel"] == "S" ? "checked=\"checked\"" : ""; ?> /><label>Sim</label> 
	  <input name="configuravel" type="radio" value="N" <?php echo $dados["configuravel"] == "N" ? "checked=\"checked\"" : ""; ?> /> <label>Não</label></td>
	</tr>
	<tr>
	  <td>Descrição</td>
	  <td><input name="descricao" type="text" id="descricao" maxlength="30" class="textBox" value="<?php echo $dados["descricao"]; ?>" /></td>
	</tr>
	<tr>
	  <td>Tradução - Pt-br</td>
	  <td><input name="traducao_ptbr" type="text" id="traducao_ptbr" maxlength="30" class="textBox" value="<?php echo $dados["traducao_ptbr"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Dificuldade</td>
	  <td><input name="dificuldade" type="text" id="dificuldade" maxlength="20" class="textBox" value="<?php echo $dados["dificuldade"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Tempo</td>
	  <td><input name="tempo" type="text" id="tempo" maxlength="45" class="textBox" value="<?php echo $dados["tempo"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Português</td>
	  <td><input name="disc_pt" type="text" id="disc_pt" maxlength="40" class="textBox" value="<?php echo $dados["disc_pt"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Discussão em Inglês</td>
	  <td><input name="disc_en" type="text" id="disc_en" maxlength="10" class="textBox" value="<?php echo $dados["disc_en"]; ?>"/></td>
	</tr>
	<tr>
	  <td>Download</td>
	  <td><input name="download" type="text" id="download" maxlength="10" class="textBox" value="<?php echo $dados["download"]; ?>"/></td>
	</tr>
	<tr>
	  <td> </td>
	  <td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>
	</tr>
  </table>
</form>
</body>
</html>

Segue também uma imagem do meu phpMyAdmin:

 

Imagem Postada

Imagem Postada

 

Obrigado,

Micael

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eae, beleza? nem sei se alguem vai me responder mais naum custa nada tentar!

 

exclui os seguintes campos:

 

da tabela Usuarios

Preferencias

Salario

Login

Senha

 

Os mesmos itens no cadastro.php e no salvar.php

 

porem, quando vou postar ele dá o seguinte erro!

 

*Erro nao foi possivel efetuar o cadastro*

 

o que pode estar acontecendo?

 

já tentei de tudo, até excluir um por um, sempre dá erro!

Compartilhar este post


Link para o post
Compartilhar em outros sites

ola Fabyo.

 

estou com esse problema aqui!

 

Parse error: syntax error, unexpected T_DNUMBER in /home/a5838727/public_html/init.php on line 37

 

o que tenho q fazer ?

 

 

para ser sincero to com muitas duvias pois sou novo nisso!

 

Como eu configuro o init , tabela e config ?

 

Eu hospedo em domínio free.

 

eu tenho o usuário e senha do mysql e um servidor que eles me dão!

 

 

estou com duvida sobre a linha BANCO não sei o que colocar no lugar dela!

 

você poderia montar esses 3 como um exemplo para mim ?

 

 

desculpe mas sou muito novo e isto é realmente o que estou procurando!

 

fico grato desde já

Compartilhar este post


Link para o post
Compartilhar em outros sites

Isso é erro de sintaxe amigo, procure na linha 37 ou 36 no arquivo init.php o problema.

 

 

Leia também sobre tratamento de erros:

 

http://forum.imasters.com.br/public/style_emoticons/default/seta.gif http://forum.imasters.com.br/index.php?showtopic=229485

Compartilhar este post


Link para o post
Compartilhar em outros sites

bem, muito bom e bem feito o sistema,

mas ao tentar modificar ele não cadastraaparecendo a mensagem que não foi possível cadastrar.

seguem os arquivos que eu alterei:

Cadastro.php

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Cadastro</title>

<style>

<!--

.textBox { border:1px solid gray; width:200px;}

-->

</style>

<link href="estilo.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<form id="form1" name="form1" method="post" action="salvar.php">

<table width="400" align="center">

<tr>

<td width="145">Nome</td>

<td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td>Sobrenome</td>

<td><input name="sobre" type="text" id="sobre" maxlength="64" class="textBox" /></td>

</tr>

<tr>

<td>Sexo</td>

<td><input name="sexo" type="radio" value="M" checked="checked" />

<label>Masculino</label>

<input name="sexo" type="radio" value="F" />

<label>Feminino</label></td>

</tr>

<tr>

<td><div align="left">Data Nascimento</div></td>

<td><input name="dia" class="input" size="2" maxlength="2" />

/

<input name="mes" class="input" size="2" maxlength="2" />

/

<input name="ano" class="input" size="5" maxlength="4" />

dd/mm/aaaa</td>

</tr>

<tr>

<td><div align="left">Data Falecimento</div></td>

<td><input name="dia2" class="input" size="2" maxlength="2" id="dia2" />

/

<input name="mes2" class="input" size="2" maxlength="2" id="mes2" />

/

<input name="ano2" class="input" size="5" maxlength="4" id="ano2" />

dd/mm/aaaa </td>

</tr>

<tr>

<td>Cidade</td>

<td><input name="cidade" type="text" id="cidade" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td>Estado</td>

<td><input name="estado" type="text" id="estado" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td> </td>

<td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>

</tr>

</table>

</form>

</body>

</html>

 

salvar.php

CODE
<?php

if($_SERVER["REQUEST_METHOD"] == "POST") {

$nome = $_POST["nome"];

$sobre = $_POST["sobre"];

$sexo = $_POST["sexo"];

$data_nasc = "$_POST[ano]-$_POST[mes]-$_POST[dia]";

$data_falec = "$_POST[ano2]-$_POST[mes2]-$_POST[dia2]";

$cidade = $_POST["cidade"];

$estado = $_POST["estado"];

 

include "config.php";

 

 

if(@mysql_query("INSERT INTO obitos VALUES ('$nome', '$sobre', '$sexo' , '$data_nasc', '$data_falec', '$cidade', '$estado' )")) {

 

if(mysql_affected_rows() == 1){

echo "Registro efetuado com sucesso<br />";

}

 

} else {

if(mysql_errno() == 1062) {

echo $erros[mysql_errno()];

exit;

} else {

echo "Erro nao foi possivel efetuar o cadastro";

exit;

}

@mysql_close();

}

 

}

?>

<a href="index.html">Voltar</a>

 

é um erro duplicar as datas? se sim como incluir outra opção como data de falecimento e nascimento?

 

agradeço o auxílio se possível

Compartilhar este post


Link para o post
Compartilhar em outros sites

alguem me diz aew como eu posso usar

esse onda com o wamp ...?

 

eh q eu sou novo ainda nessas ondas...

 

e um amigo meu disse pra eu usar esse wamp...

 

por favor

 

abraçosss

Compartilhar este post


Link para o post
Compartilhar em outros sites

Parabés Fabyo pelo seu tópico, nele conseguir ver que tem muitas funções para se estudar...

Só posso dizer uma coisa, continue assim cara vai chegar longe...

Espero um dia estar postando algum artigo que ajude a galera tambem...

Estou começando agora com php e estou aprendendo muito aqui no forum com pessoas como você.

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.