Foros del Web » Programando para Internet » PHP »

Recoger variable con $_GET para en editar noticia

Estas en el tema de Recoger variable con $_GET para en editar noticia en el foro de PHP en Foros del Web. Estoy trabajando sobre el sistema de noticias y me gustaria poder editar las noticias una vez publicadas. Pero no consigo obtener la id de la ...
  #1 (permalink)  
Antiguo 22/05/2011, 17:32
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 12 años, 11 meses
Puntos: 4
Recoger variable con $_GET para en editar noticia

Estoy trabajando sobre el sistema de noticias y me gustaria poder editar las noticias una vez publicadas. Pero no consigo obtener la id de la noticia para actualizarla, a ver si me pueden echar una mano. Gracias:

list-noticia.campeonatos.php
Código PHP:
<?
// verificamos si se ha enviado
// alguna variable via GET
if(isset($_GET['id']) && $_GET['categoria']){
    
// asignamos los valores
    // a las variables que usaremos
    
$cat_ID $_GET['id'];
    
$categoria $_GET['categoria'];
}
// armamos la consulta
$sqlQueryNot mysql_query("SELECT not_ID, notTitulo, notTexto, foto FROM sn_noticias where notCategoriaID='1' ORDER BY not_ID DESC LIMIT 4"$db_link) or die(mysql_error);
//Declarar el array 
$not_ID = array(not_ID);
$ArrayTitulo = array(notTitulo);
$ArrayTexto = array(notTexto); 
$Arrayfoto = array(foto); 
   
  while(
$rowNot mysql_fetch_array($sqlQueryNot)){ 
$not_ID[]= $rowNot[not_ID];                     
$ArrayTitulo[]= $rowNot[notTitulo];
$ArrayTexto[]= $rowNot[notTexto];
$Arrayfoto[]= $rowNot[foto];
}
 
?>   
<body bgcolor="#FFE821">

<div style="position: absolute; left: 280; top: 230; width: 240; height: 909; float:left">

<table border="0" cellpadding="0" cellspacing="0"  width="279"  bgcolor="#ffffff">

<?include("docs/esquinasarriba.txt");?>

<td class="fondoblanco">

<table width="257">

<tr>

<td colspan="2" align="center"><font color="#ff7f00"><b>CAMPEONATOS</b></font>

</td>

</tr>

<tr>
<td colspan="2" align="center"><a href="/resultadoscv2011.php">Palmares Equipos 2011</a></td>
</tr>"

<tr>
<td align="left"><a href="docs/*.pdf">Ranking Masculino</a></td>
<td align="right"><a href="docs/*.pdf">Ranking Femenino</a></td>
</tr>

</table>

<HR>


<table class="fondoblanco" width="257">

<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[1]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[1]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[1]; ?>"><img src="imagesr/<? echo $Arrayfoto[1]; ?>"
width="100" height="100"><br><br>
<a href="editar.php?id=<?echo $not_ID[1];?>">Editar Noticia</a>

<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->

<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[2]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[2]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[2]; ?>"><img src="imagesr/<? echo $Arrayfoto[2]; ?>" width="100" height="100"><br><br>
<a href="editar.php?id=<?echo $not_ID[2];?>">Editar Noticia</a>
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->




<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[3]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[3]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[3]; ?>"><img src="imagesr/<? echo $Arrayfoto[3]; ?>" width="100" height="100"><br><br>
<a href="editar.php?id=<? echo$not_ID[3];?>">Editar Noticia</a>
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->




<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[4]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[4]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[4]; ?>"><img src="imagesr/<? echo $Arrayfoto[4]; ?>" width="100" height="100"><br><br>
<a href="editar.php?id=<? echo$not_ID[4];?>">Editar Noticia</a>
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->


</table>




<?include("docs/esquinasabajo.txt");?>

</table>
<br><br>
</div>
</body>
Quiero coger el valor que me da $not_ID[1] por ejemplo y usarlo en editar.php

Código PHP:
<?

//recibimos la variable id enviada en el enlace por GET
$id=$_GET['not_ID[]'];
//conectamos a la base
include ('db-cnx.php');

//hacemos las consultas
$result=mysql_query("select notTitulo, notTexto, notCategoriaID, foto from sn_noticias where not_ID='$id'",$db_link) or die(mysql_error());
//Una vez seleccionados los registros los mostramos para su edición
while($row=mysql_fetch_array($result)) {
echo

    <form name="noticia" action="edit.php" method="post" enctype="multipart/form-data"
>
<body bgcolor="#FFE821">
<input type="hidden" name="id" value="'
.$row[not_ID].'"><br> 

<p>
Título de la Noticia<br />
<input type="text" name="notTitulo" size="50" value="'
.$row[notTitulo].'" />
</p>
<p>
Texto de la Noticia<br />
<textarea name="notTexto" rows="10" cols="50">'
.$row[notTexto].'</textarea>
</p>
<p>
Inserta imagen<br />
<input type="file" name="foto" value="'
.$row[foto].' size="50" />
<p>
Categoría<br />
<select name="notCategoriaID">

<option value="">Escoger de la Lista</option>


<?php
// asignamos una categoria a la noticia
// mediante un select
$sqlQueryCat = mysql_query("SELECT * FROM sn_categorias", $db_link)
or die(mysql_error());
// creamos un bucle while
// que nos muestre todas las categorias
// que tenemos guardadas en la BD
while($rowCat = mysql_fetch_array($sqlQueryCat)){
echo "<option value='
$rowCat[cat_ID]'>$rowCat[catCategoria]</option>";
}
?>
</select>
</p>
<p>
<input type="submit" value="Editar" />
</p>
</form>'
}
    
    
mysql_free_result($result);mysql_close($db_link);
  
  
 
?>
edit.php

Código PHP:
<? 
//conectamos a la base 
include ('db-cnx.php');
//recibimos las variables enviadas por el formulario 
$id=$_POST[id]; 
$notTitulo=$_POST[notTitulo]; 
$notTexto=$_POST[notTexto];
$notCategoriaID=$_POST[notCategoriaID]; 
$nombre_archivo $_FILES["foto"]["name"];  
$tipo_archivo $_FILES["foto"]["type"];  
$tamano_archivo $_FILES["foto"]["size"];

if (!((
strpos($tipo_archivo"gif") || strpos($tipo_archivo"jpeg")) && (    $tamano_archivo 1000000))) 
{  
    echo 
"La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 1Mg máximo.</td></tr></table>";
}
else 
{  
    
$nom_img$nombre_archivo
     
    
$directorio 'imagesr/';
    if (
move_uploaded_file($_FILES['foto']['tmp_name'],$directorio "/" $nom_img)) 
    { 
    
    
//Hacemos insert de la edicion
    
    
$sqlinserteditmysql_query("UPDATE sn_noticias SET notTitulo='$notTitulo',notTexto='$notTexto',notCategoriaID='$notCategoriaID',foto='$nom_img' where not_ID='$id'",
$db_link) or die(mysql_error());
 

echo 
"La noticia se edito correctamente.";
}else{
    echo 
"Error al subir la foto.";
}

header("location: indexr.php"); 
?>
Seguramente tendre muchas cosas mal en los scripts, agradezco vuestro tiempo.
  #2 (permalink)  
Antiguo 23/05/2011, 08:49
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Recoger variable con $_GET para en editar noticia

Entonces te invito a leer lo siguiente:
http://www.php.net/variables.external

Por que si tienes bastantes cosas mal, por eso ve a estudiar.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.

Etiquetas: noticia, recoger, variables
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 15:46.