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

Ueki te pongo todo lo que tengo hecho para ver si me puedes ayudar sobre esto, perdona que sea tan pesado:

Te explico lo que necesitaria y te paso lo que tengo hecho a ver si me puedes ayudar: Quiero que el usuario usando el formulario inserte el texto y titulo de la noticia y si quiere pueda subir una imagen con la noticia para poder publicarla.

Te paso lo que tengo hecho:

CONEXION A LA BASE DE DATOS
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());
}
?>

AÑADIR NOTICIA

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" enctype='multipart/form-data'>
<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>
Inserta imagen
<input name="notFoto" type='file' /><br><br>
<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>

PUBLICAR NOTICIA
list-noticia-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>

BASE DE DATOS
sn_noticias
(base de datos)
CREATE TABLE `sn_noticias` (
`not_ID` int(11) NOT NULL auto_increment,
`notTitulo` varchar(255) NOT NULL,
`notTexto` text NOT NULL,
`notCategoriaID` int(11) NOT NULL,
PRIMARY KEY (`not_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=39 ;