Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/05/2011, 02:26
cabritillo77
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 13 años
Puntos: 4
Subir imagenes en un sistema de noticias

Recurro a posterar pues he estado buscando y no he encontrado lo que buscaba ni me sale el codigo por mi mismo. La idea es que tengo un sistema de noticias al que quisiera poder subir imagenes que acompañen a cada noticia. Os pongo los codigos para que veais lo que tengo. Quisiera que el formulario diese la opcion de subir imagenes y estas aparezcan, si se han subido, bajo el texto que presenta cada noticia. Gracias de antemano por la ayuda.
1)Conexion
db-cnx.php
<?php
$db_link = mysql_connect('host', 'user', 'pass');
if(!$db_link){
die('No se pudo conectar: ' . mysql_error());
}
$db_selected = mysql_select_db('db', $db_link);
if(!$db_selected){
die('No se selecciono la BD: ' . mysql_error());
}
?>
2)Añadir noticias
add-noticia.php
<?php
// incluimos el archivo de conexion
include ('db-cnx.php');
// recibimos el formulario
if(isset($_POST['enviar']) && $_POST['enviar'] == 'Enviar'){
// comprobamos que el formulario no envie campos vacios
if(!empty($_POST['notTitulo']) && $_POST['notTexto'] &&
$_POST['notCategoriaID']){
// creamos las variables y les asignamos los valores a insertar
$notTitulo = $_POST['notTitulo'];
$notTexto = $_POST['notTexto'];
$notCategoriaID = $_POST['notCategoriaID'];
$notTitulo = strtoupper ($notTitulo);
// hacemos el INSERT en la BD
$sqlInsertNot = mysql_query("INSERT INTO sn_noticias
(notTitulo, notTexto, notCategoriaID)
VALUES ('$notTitulo', '$notTexto', '$notCategoriaID')",
$db_link) or die(mysql_error());
// enviamos un mensaje de exito
echo "Los datos fueron gurdados correctamente";
}else{
// si el formulario envia algun campo vacio
// enviamos un mensaje de error
echo "Debe llenar todos los campos del formulario";
}
}

?>
<!-- el formulario -->
<div style="position: absolute; left: 300; top: 50; width: 300; height: 500">
<form name="noticia" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<body bgcolor="#FFE821">
<p>
Título de la Noticia<br />
<input type="text" name="notTitulo" size="50" />
</p>
<p>
Texto de la Noticia<br />
<textarea name="notTexto" rows="10" cols="50"></textarea>
</p>
<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" name="enviar" value="Enviar" />
</p>
</form>
<br><br>
<a href="indexr.php">Ver Noticias</a>
<br><br>
<a href="add.categoria.php">Añadir Nueva Categoria</a>

</div>
Mostar noticias:
list-noticias-campeonatos.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 notTitulo, notTexto FROM sn_noticias where notCategoriaID='1' ORDER BY not_ID DESC LIMIT 4", $db_link) or die(mysql_error);
//Declarar el array
$ArrayTitulo = array(notTitulo);
$ArrayTexto = array(notTexto);

while($rowNot = mysql_fetch_array($sqlQueryNot)){
$ArrayTitulo[]= $rowNot[notTitulo];
$ArrayTexto[]= $rowNot[notTexto];
}
?>
<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/CLUB DE TENIS TORREVIEJA-M.pdf">Ranking Masculino</a></td>
<td align="right"><a href="docs/CLUB DE TENIS TORREVIEJA-F.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>
<p>
<? echo $ArrayTexto[1]; ?>
<br><br>
</p>

<br><br>

<hr>
</td>
</tr>

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

<tr>

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

</td>
</tr>

<tr>
<td>
<p>
<? echo $ArrayTexto[2]; ?>
<br><br>
</p>

<br><br>

<hr>
</td>
</tr>

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




<tr>

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

</td>
</tr>

<tr>
<td>
<p>
<? echo $ArrayTexto[3]; ?>
<br><br>
</p>

<br><br>

<hr>
</td>
</tr>

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




<tr>

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

</td>
</tr>

<tr>
<td>
<p>
<? echo $ArrayTexto[4]; ?>
<br><br>
</p>

<br><br>

<hr>
</td>
</tr>

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


</table>




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

</table>
<br><br>
</div>
</body>