Ir para conteúdo

POWERED BY:

Arquivado

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

patricias

formulario para editar BD

Recommended Posts

:( pessoal,o formulario para editar dados no banco, é o mesmo formulario que utiliza-se para cadastrar os dados, certo?a diferença (é logico) está no comando a ser executado...no caso para editar...certo?Alguem pode me dizer qual seria esse comando do sql, onde eu edito um dado no BD através do ID?eu tenho 2 tabelas....nessas 2 tabelas, tenho id_noticia e id_galeria (galeria de fotos)....como chamo esse id (correto) para editar esses dados?valeu!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Mas tb uso select??

O comando a ser utilizado é o update:update tabela set campo = 'x' where id = 1;Mais ou menos assim....

Compartilhar este post


Link para o post
Compartilhar em outros sites

veja isso:

UPDATE noticias SET titulo=%s, noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE id=%s

ta certo?

não.no exemplo que passei, você estaria colocando o valor x na coluna campo do registro cuja id é igual a 1.

Compartilhar este post


Link para o post
Compartilhar em outros sites

O lance é q eu clico na noticia pra editar, ele me mostra a id da noticia, pq qdo quero ler a noticia aparece a id correta....mas na hora de editar...ele sempre mostra a noticia 1, mesmo no link estando por ex. noticia 54isso q nao to entendendo...

Compartilhar este post


Link para o post
Compartilhar em outros sites

o lance é desencanar dessas coisas prontas de dreamweaver...

eu faço assim para formulario de inclusão e alteração...

 

no começo, verifico se é inclusão ou alteração pelo parâmetro id (ou código), que é a chave auto-increment...

 

if(!isset($_REQUEST['id'])) {$acao = "insert";}else {$acao = "update";//aqui define a conexão ao bd e bla bla bla//e faz a query$sql_query = "select * from tabela_que_vc_quer where id = ".$_REQUEST['id'];//executa a query e faz o mysql_fetch_assoc() do resultset//ai define os valores, por exemplo $nome = $col_Resultset_query['nome'];...}

no campo nome por exemplo, eu jogo

<input type="text" name="nome" value="<?php echo $nome; ?>" />

e no final do formulario um hidden chamado acao e com o value igual à variável acao...

 

tá aí o lance é pro script que vai gravar os dados....

 

testa a variavel acao...

 

if($_REQUEST['acao'] == "insert") {$query_sql = "insert into bla bla bla...";}if($_REQUEST['acao'] == "update") {$query_sql = "update tabela set bla bla bla where id = '"$_REQUEST['id'];}

é claro, isso é o jeito super básico, você adapta à sua maneira =)

 

abraço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

está sim!!!ta errado??

Patricias parece que você está usando o Dreamweaver, estou certo?

Vou tentar explicar com criar o update com dreamweaver:Voupartir do princípio que a conexão com o BD esteja criada.1- Crie um recordset.Vá em aplication/recordset, na janela que aparecer coloque o nome para o recorset, escolha a conexão do BD que vai usar, escolha a tabela que deseja, marque os campos da tabela que queira ou deixe a opção ALL(todos),em filter escolha a chave primária de sua tabela, no campo a frente deixe =, no campo abaixo escolha url parameter, clique em ok.2- Agora vamos criar o formulário, crie um record update form wizard:Vá em aplication/update record/record update form wizard, escolha a conexão do BD que está usando, escolha a tabela que quer atualizar, escolha o nome do recordset que está usando, escolha a página para a qual vai ser redirecionado depois que fizer o update, os campos que irão aparecer no formulário, em baixo escolha o nome que vai aparecer em cada label do formulário, já serão colocados automáticamente, caso queira mudar, mude-os, em display as escolha o tipo de cada objeto do formulário(textfild, button....), mais embaixo texto dinâmico para cada objeto colocado no form, o texto dinâmico seria o 'Value', só que será mostrado o valor que está na tabela do BD,este item também aparecerá automáticamente, mudeo se precisar. Clique OK.pronto o seu update está montado, configure agora o seu form como queira, quando for chamar este update, é só passar a variável que é a chave primária da tabela. Espero que entenda, qualquer coisa posta aí.

Compartilhar este post


Link para o post
Compartilhar em outros sites

oi hcar,do jeito que você falou, consegui ao menos "chegar" na noticia, acontece, q nada acontece rs....altero e nada é alterado no banco....tem como eu saber oq ou onde tem erro?, por ex. surgiu uma duvida na hora de montar o formulario....Nas colunas...aparecem os campos do form.....ai pedepra q eu determine um primary key e um integer...o que ser isso??? é alguma associacao?se eu deixo o ID apenas como primary key, aparece uma janela com a msg: "Please submit a least one column as primary key"

Compartilhar este post


Link para o post
Compartilhar em outros sites

oi hcar,do jeito que você falou, consegui ao menos "chegar" na noticia, acontece, q nada acontece rs....altero e nada é alterado no banco....tem como eu saber oq ou onde tem erro?, por ex. surgiu uma duvida na hora de montar o formulario....Nas colunas...aparecem os campos do form.....ai pedepra q eu determine um primary key e um integer...o que ser isso??? é alguma associacao?se eu deixo o ID apenas como primary key, aparece uma janela com a msg: "Please submit a least one column as primary key"

acredito que você não esteja setando em 'unique key column', a sua chave primária, ou seja nesta opção você seta a chave primária da tabela, se for um número deixa a opção numeric marcada senão desmarque-a.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Continuo ainda sem conseguir alterar o banco.Aparece a noticia correta, agora consigo visualizar realmente a noticia que quero alterar, porem, nada acontece após o submit....O que pode ser?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pessoal,o problema agora esta assim: eu visualizo a noticia a ser editada, faco as alteracoes...e nada acontece....ao clicar no submit.....segue o codigo

<?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "Editar")) { $updateSQL = sprintf("UPDATE noticias SET titulo=%s, noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE id=%s", GetSQLValueString($_POST['titulo'], "text"), GetSQLValueString($_POST['noticia'], "text"), GetSQLValueString($_POST['destaque'], "text"), GetSQLValueString($_POST['subtitulo'], "text"), GetSQLValueString($_POST['setor'], "text"), GetSQLValueString($_POST['titulo'], "int")); mysql_select_db($database_noticias, $noticias); $Result1 = mysql_query($updateSQL, $noticias) or die(mysql_error()); $updateGoTo = "editarOK.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo));}$colname_EditarNoticias = "-1";if (isset($_GET['id'])) { $colname_EditarNoticias = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);}mysql_select_db($database_noticias, $noticias);$query_EditarNoticias = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_EditarNoticias);$EditarNoticias = mysql_query($query_EditarNoticias, $noticias) or die(mysql_error());$row_EditarNoticias = mysql_fetch_assoc($EditarNoticias);$totalRows_EditarNoticias = mysql_num_rows($EditarNoticias);?>

abaixo desse codigo vem o form

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pessoal,o problema agora esta assim: eu visualizo a noticia a ser editada, faco as alteracoes...e nada acontece....ao clicar no submit.....segue o codigo

<?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "Editar")) { $updateSQL = sprintf("UPDATE noticias SET titulo=%s, noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE id=%s", GetSQLValueString($_POST['titulo'], "text"), GetSQLValueString($_POST['noticia'], "text"), GetSQLValueString($_POST['destaque'], "text"), GetSQLValueString($_POST['subtitulo'], "text"), GetSQLValueString($_POST['setor'], "text"), GetSQLValueString($_POST['titulo'], "int")); mysql_select_db($database_noticias, $noticias); $Result1 = mysql_query($updateSQL, $noticias) or die(mysql_error()); $updateGoTo = "editarOK.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo));}$colname_EditarNoticias = "-1";if (isset($_GET['id'])) { $colname_EditarNoticias = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);}mysql_select_db($database_noticias, $noticias);$query_EditarNoticias = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_EditarNoticias);$EditarNoticias = mysql_query($query_EditarNoticias, $noticias) or die(mysql_error());$row_EditarNoticias = mysql_fetch_assoc($EditarNoticias);$totalRows_EditarNoticias = mysql_num_rows($EditarNoticias);?>

abaixo desse codigo vem o form
seu erro é que você não setou a chave primária corretamente, esta linha aqui mostra isso:GetSQLValueString($_POST['titulo'], "int"));no lugar de 'título' seria o nome do campo de sua chave primária(id) , verifica no seu form se tem esses campos hiden:<input type="hidden" name="MM_update" value="form1"><input type="hidden" name="id" value="<?php echo $row_rsUpdate['id']; ?>">se tiver é só no lugar de 'título', colocar 'id'.Preste atenção que 'id' que me refiro é a chave primária da tabela.

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz o que você falou....

 

porem, nao consigo atualizar nenhum campo.... http://forum.imasters.com.br/public/style_emoticons/default/upset.gif

 

<?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;  switch ($theType) {	case "text":	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";	  break;		case "long":	case "int":	  $theValue = ($theValue != "") ? intval($theValue) : "NULL";	  break;	case "double":	  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";	  break;	case "date":	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";	  break;	case "defined":	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;	  break;  }  return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) {  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editar")) {  $updateSQL = sprintf("UPDATE noticias SET noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE titulo=%s",					   GetSQLValueString($_POST['titulo'], "text"),					   GetSQLValueString($_POST['noticia'], "text"),					   GetSQLValueString($_POST['destaque'], "text"),					   GetSQLValueString($_POST['subtitulo'], "text"),					   GetSQLValueString($_POST['setor'], "text"),					   GetSQLValueString($_POST['id'], "int"));  mysql_select_db($database_conexao, $conexao);  $Result1 = mysql_query($updateSQL, $conexao) or die(mysql_error());  $updateGoTo = "editarOK.php";  if (isset($_SERVER['QUERY_STRING'])) {	$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";	$updateGoTo .= $_SERVER['QUERY_STRING'];  }  header(sprintf("Location: %s", $updateGoTo));}$colname_EditarNoticias = "1";if (isset($_GET['id'])) {  $colname_EditarNoticias = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);}mysql_select_db($database_conexao, $conexao);$query_EditarNoticias = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_EditarNoticias);$EditarNoticias = mysql_query($query_EditarNoticias, $conexao) or die(mysql_error());$row_EditarNoticias = mysql_fetch_assoc($EditarNoticias);$totalRows_EditarNoticias = mysql_num_rows($EditarNoticias);?><form class="formgeral" action="<?php echo $editFormAction; ?>" method="post" name="editar" enctype="multipart/form-data"><fieldset><legend class="titulo">Inserir Notícias:</legend><table width="200" border="0">  <tr>	<td width="104" class="subtitulo"><span class="style9">	  <label></label>	  <span class="subtitulo">ID da Noticia </span></span></td>	<td colspan="2"><strong class="cornegrito"><?php echo $row_EditarNoticias['id']; ?></strong></td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">	  <label>Título:</label>	</span></td>	<td colspan="2"><input name="titulo" type="text" class="TextBox3" id="titulo" value="<?php echo $row_EditarNoticias['titulo']; ?>" size="60"></td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">	  <label>SubTítulo:</label>	</span></td>	<td colspan="2"><input name="subtitulo" type="text" class="TextBox3" id="subtitulo" value="<?php echo $row_EditarNoticias['subtitulo']; ?>" size="60"></td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">	  <label>Notícia:</label>	</span></td>	<td colspan="2" rowspan="7"><textarea name="noticia" id="noticia" cols="60" rows="20" class="TextBox3"><?php echo $row_EditarNoticias['noticia']; ?></textarea></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr class="subtitulo">	<td><span class="style10"></span></td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">	  <label>Setor: </label>	</span></td>	<td colspan="2">		<select name="setor" class="TextBox3" id="setor">		  <option>Administracao</option>			<option>Controle_Interno</option>			<option>Educação</option>				</select>	</td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">Destaque: </span></td>	<td width="97">		<label><span class="TextBox3"><strong>		<input name="destaque" type="radio" id="destaque" value="sim">		SIM</strong></span></label>		<span class="TextBox3"><strong>		<label>		<input name="destaque" type="radio" id="destaque"  value="nao">		NÃO</label>	  </strong></span><span class="TextBox3"> </span></td>	<td width="183" class="texto"><div align="right"><span class="subtitulo">Essa notícia está classificada como:</span><span class="Button1"><?php echo $row_EditarNoticias['destaque']; ?></span> <br />	</div></td>  </tr>  <tr>	<td class="subtitulo"><span class="style9">	  <label>Imagem: </label>	</span></td>	<td colspan="2"><input type="file" id="imagem" name="imagem" class="TextBox3" size="50"></td>  </tr>  <tr>	<td colspan="3"><label><img src="<?php echo $row_EditarNoticias['foto']; ?>" alt="imagem" class="moldura" /></label></td>	</tr>    <tr>	<td> </td>	<td colspan="2">		<table width="208" border="0" align="center" cellpadding="0" cellspacing="1">		  <tr>			<td width="110"><div align="center">			  <input name="Submit" type="submit" class="Button1" value="Editar" />			</div></td>			<td width="95"><div align="center">			  <input name="Submit2" type="reset" class="Button1" id="Submit2" value="Cancelar" />			</div></td>		  </tr>		</table>	  </td>  </tr></table><a href="?categoria=" class="link">Voltar</a></fieldset><input type="hidden" name="MM_update" value="editar"><input type="hidden" name="id" value="<?php echo $row_rsUpdate['id']; ?>"></form><?phpmysql_free_result($EditarNoticias);?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editar")) {

$updateSQL = sprintf("UPDATE noticias SET titulo=%s, noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE id=%s",

GetSQLValueString($_POST['titulo'], "text"),

GetSQLValueString($_POST['noticia'], "text"),

GetSQLValueString($_POST['destaque'], "text"),

GetSQLValueString($_POST['subtitulo'], "text"),

GetSQLValueString($_POST['setor'], "text"),

GetSQLValueString($_POST['id'], "int"));

 

mysql_select_db($database_conexao, $conexao);

$Result1 = mysql_query($updateSQL, $conexao) or die(mysql_error());

 

$updateGoTo = "editarOK.php";

if (isset($_SERVER['QUERY_STRING'])) {

$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

$updateGoTo .= $_SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $updateGoTo));

}

 

$colname_EditarNoticias = "1";

if (isset($_GET['id'])) {

$colname_EditarNoticias = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);

}

mysql_select_db($database_conexao, $conexao);

$query_EditarNoticias = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_EditarNoticias);

$EditarNoticias = mysql_query($query_EditarNoticias, $conexao) or die(mysql_error());

$row_EditarNoticias = mysql_fetch_assoc($EditarNoticias);

$totalRows_EditarNoticias = mysql_num_rows($EditarNoticias);

?>

 

<form class="formgeral" action="<?php echo $editFormAction; ?>" method="post" name="editar" enctype="multipart/form-data">

<fieldset>

<legend class="titulo">Inserir Notícias:</legend>

<table width="200" border="0">

<tr>

<td width="104" class="subtitulo"><span class="style9">

<label></label>

<span class="subtitulo">ID da Noticia </span></span></td>

<td colspan="2"><strong class="cornegrito"><?php echo $row_EditarNoticias['id']; ?></strong></td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">

<label>Título:</label>

</span></td>

<td colspan="2"><input name="titulo" type="text" class="TextBox3" id="titulo" value="<?php echo $row_EditarNoticias['titulo']; ?>" size="60"></td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">

<label>SubTítulo:</label>

</span></td>

<td colspan="2"><input name="subtitulo" type="text" class="TextBox3" id="subtitulo" value="<?php echo $row_EditarNoticias['subtitulo']; ?>" size="60"></td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">

<label>Notícia:</label>

</span></td>

<td colspan="2" rowspan="7"><textarea name="noticia" id="noticia" cols="60" rows="20" class="TextBox3"><?php echo $row_EditarNoticias['noticia']; ?></textarea></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr class="subtitulo">

<td><span class="style10"></span></td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">

<label>Setor: </label>

</span></td>

<td colspan="2">

<select name="setor" class="TextBox3" id="setor">

<option>Administracao</option>

<option>Controle_Interno</option>

<option>Educação</option>

 

</select> </td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">Destaque: </span></td>

<td width="97">

<label><span class="TextBox3"><strong>

<input name="destaque" type="radio" id="destaque" value="sim">

SIM</strong></span></label>

<span class="TextBox3"><strong>

<label>

<input name="destaque" type="radio" id="destaque" value="nao">

NÃO</label>

</strong></span><span class="TextBox3"> </span></td>

<td width="183" class="texto"><div align="right"><span class="subtitulo">Essa notícia está classificada como:</span><span class="Button1"><?php echo $row_EditarNoticias['destaque']; ?></span> <br />

</div></td>

</tr>

<tr>

<td class="subtitulo"><span class="style9">

<label>Imagem: </label>

</span></td>

<td colspan="2"><input type="file" id="imagem" name="imagem" class="TextBox3" size="50"></td>

</tr>

<tr>

<td colspan="3"><label><img src="<?php echo $row_EditarNoticias['foto']; ?>" alt="imagem" class="moldura" /></label></td>

</tr>

 

<tr>

<td> </td>

<td colspan="2">

<table width="208" border="0" align="center" cellpadding="0" cellspacing="1">

<tr>

<td width="110"><div align="center">

<input name="Submit" type="submit" class="Button1" value="Editar" />

</div></td>

<td width="95"><div align="center">

<input name="Submit2" type="reset" class="Button1" id="Submit2" value="Cancelar" />

</div></td>

</tr>

</table> </td>

</tr>

</table>

<a href="?categoria=" class="link">Voltar</a>

</fieldset>

<input type="hidden" name="MM_update" value="editar">

<input type="hidden" name="id" value="<?php echo $row_rsUpdate['id']; ?>">

</form>

 

<?php

mysql_free_result($EditarNoticias);

?>

 

encontrei dois erros no seu código, testa aí agora, só duas perguntinhas, cadê a conexão com o BD que fica no começo da página:

 

<?php require_once('../Connections/bd.php'); ?>

 

outra: quando vo~cê acessa esta página os campos do form estão sendo preenchidos?

 

os erros estão destacados no texto

Compartilhar este post


Link para o post
Compartilhar em outros sites

Respondendo tuas 2 perguntas,a conexao está lá emcima, eu só não colei no forum...sim,qdo acesso os campos do form aparecem preenchidos, porem, as alteracoes é q nao estao indo pro banco....mas vou testar agora com oq você fez....brigada

...encontrei dois erros no seu código, testa aí agora, só duas perguntinhas, cadê a conexão com o BD que fica no começo da página:<?php require_once('../Connections/bd.php'); ?>outra: quando vo~cê acessa esta página os campos do form estão sendo preenchidos?os erros estão destacados no texto

Compartilhar este post


Link para o post
Compartilhar em outros sites

Realmente não sei o que está acontecendo...onde estou errando.....O FOrmulario vem "preenchido", mas as alteracoes não vão para o banco, e não da erro algum....chego na pagina de edicaoOK, "noticia editada com sucesso"..mas vou consultar o banco...e nada...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pessoal, continuo com esse problema , alguem pode me ajudar???

 

Detalhe, coloquei no formulario uma linha

ID da Noticia {EditarNoticias.id}

 

ai ele faz o seguinte, na barra de endereco, vem assim: http://localhost/noticias/admin/editar.php?id=34

 

Mas na linha do formulario aparece apenas a id da primeira noticia!

 

os campos restantes aparecem referente a noticia certa, ai qdo altero e peco pra ele mudar...ele nao muda!!!

 

como pode isso????

Compartilhar este post


Link para o post
Compartilhar em outros sites

Codigo:

<?php require_once('../../Connections/conexao.php'); ?><?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editar")) { $updateSQL = sprintf("UPDATE noticias SET noticia=%s, destaque=%s, subtitulo=%s, setor=%s WHERE id=%s", GetSQLValueString($_POST['titulo'], "text"), GetSQLValueString($_POST['noticia'], "text"), GetSQLValueString($_POST['destaque'], "text"), GetSQLValueString($_POST['subtitulo'], "text"), GetSQLValueString($_POST['setor'], "text"), GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_conexao, $conexao); $Result1 = mysql_query($updateSQL, $conexao) or die(mysql_error()); $updateGoTo = "editarOK.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo));}mysql_select_db($database_conexao, $conexao);$query_EditarNoticias = "SELECT * FROM noticias WHERE noticias.id";$EditarNoticias = mysql_query($query_EditarNoticias, $conexao) or die(mysql_error());$row_EditarNoticias = mysql_fetch_assoc($EditarNoticias);$totalRows_EditarNoticias = mysql_num_rows($EditarNoticias);?><style type="text/css"><!--.style2 {font-weight: bold}.style3 {color: #FF0000}--></style><link href="../../css/prefeitura.css" rel="stylesheet" type="text/css"><form class="formgeral" action="<?php echo $editFormAction; ?>" method="post" name="editar" enctype="multipart/form-data"><fieldset><legend class="titulo">Inserir Notícias:</legend><table width="200" border="0"> <tr> <td width="104" class="subtitulo"><span class="style9"> <label>Título:</label> </span></td> <td colspan="2"><input name="titulo" type="text" class="TextBox3" id="titulo" value="<?php echo $row_EditarNoticias['titulo']; ?>" size="60"></td> </tr> <tr> <td class="subtitulo"><span class="style9"> <label>SubTítulo:</label> </span></td> <td colspan="2"><input name="subtitulo" type="text" class="TextBox3" id="subtitulo" value="<?php echo $row_EditarNoticias['subtitulo']; ?>" size="60"></td> </tr> <tr> <td class="subtitulo"><span class="style9"> <label>Notícia:</label> </span></td> <td colspan="2" rowspan="7"><textarea name="noticia" id="noticia" cols="60" rows="20" class="TextBox3"><?php echo $row_EditarNoticias['noticia']; ?></textarea></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr class="subtitulo"> <td><span class="style10"></span></td> </tr> <tr> <td class="subtitulo"><span class="style9"> <label>Setor: </label> </span></td> <td colspan="2"> <select name="setor" class="TextBox3" id="setor"> <option>Administracao</option> <option>Controle_Interno</option> <option>Educação</option> <option>Esporte e Lazer</option> <option>Gabinete do Prefeito</option> <option>Guarda Municipal</option> <option>Meio Ambiente</option> <option>Obras</option> <option>Planejamento</option> <option>Promoção Social</option> <option>Saúde</option> <option>Turísmo</option> </select> </td> </tr> <tr> <td class="subtitulo"><span class="style9">Destaque: </span></td> <td width="97"> <label><span class="TextBox3"><strong> <input name="destaque" type="radio" id="destaque" value="sim"> SIM</strong></span></label> <span class="TextBox3"><strong> <label> <input name="destaque" type="radio" id="destaque" value="nao"> NÃO</label> </strong></span><span class="TextBox3"> </span></td> <td width="183" class="texto"><div align="right"><span class="subtitulo">Essa notícia está classificada como:</span><span class="Button1"><?php echo $row_EditarNoticias['destaque']; ?></span> <br /> </div></td> </tr> <tr> <td class="subtitulo"><span class="style9"> <label>Imagem: </label> </span></td> <td colspan="2"><input type="file" id="imagem" name="imagem" class="TextBox3" size="50"></td> </tr> <tr> <td colspan="3"><label><img src="<?php echo $row_EditarNoticias['foto']; ?>" alt="imagem" class="moldura" /></label></td> </tr> <tr> <td> </td> <td colspan="2"> <table width="208" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="110"><div align="center"> <input name="Submit" type="submit" class="Button1" value="Editar" /> </div></td> <td width="95"><div align="center"> <input name="Submit2" type="reset" class="Button1" id="Submit2" value="Cancelar" /> </div></td> </tr> </table> </td> </tr></table><a href="?categoria=" class="link">Voltar</a></fieldset><input type="hidden" name="MM_update" value="editar"><input type="hidden" name="id" value="<?php echo $row_rsUpdate['id']; ?>"></form><?phpmysql_free_result($EditarNoticias);?>

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.