96
« en: 02 de Febrero de 2010, 02:58:20 am »
Buenos amigos estoy haciendo un sistema de noticia, cuando envia el formulario esta bien pero cuando veo la base de datos no hay nada guardado, tambien le doy a ver noticia me da un error aqui les dejo lo que estoy haciendo y mi codigo "Ojo: Este Sistema de Noticia es para un Panel de Control de Admin"
CREATE TABLE noticia (
id int (1) NOT NULL auto_increment,
titulo char (100) NOT NULL,
noticia text NOT NULL,
fecha datetime NOT NULL,
autor char (100) NOT NULL,
key id (id))
Noticia.php
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<blockquote>
<form action="enviar.php" method="post" name="form" id="form">
<table width="314" border="0">
<tr>
<td width="85"><strong>Titulo:</strong></td>
<td width="219"><label>
<input name="titulo" type="text" id="titulo">
</label></td>
</tr>
<tr>
<td><strong>Autor:</strong></td>
<td><label>
<input name="autor" type="text" id="autor">
</label></td>
</tr>
<tr>
<td><strong>Fecha:</strong></td>
<td><label>
<select name="days" id="days">
<?php
for($i = 1; $i <= date("t"); $i++) {
$i==date("d") ? $amount = "selected" : $amount = "";
$i<=9 ? $zero = "0" : $zero = "";
echo "<option value='$zero$i' $amount>$zero$i</option>";
}
?>
</select>
</label>
/
<label>
<select name="months" id="months">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<?php
for($i = 1; $i <= count($months)-1; $i++) {
$i == $date ? $amount = "selected" : $amount = "";
echo "<option value='$months[$i]' $amount>$months[$i]</option>";
}
?>
</select>
</label>
/
<label>
<select name="years" id="years">
<?php
for($i = 1950; $i <= date("Y"); $i++) {
$i==date("Y") ? $amount = "selected" : $amount = "";
echo "<option value='$i' $amount>$i</option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td><strong>
<label>Mensaje:</label>
</strong></td>
<td><label></label>
<label></label><label>
<textarea name="mensaje" cols="25" rows="10" id="mensaje"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<p>
<label>
<input name="ok" type="submit" id="ok" value="Enviar Noticia">
</label>
<label>
<input type="reset" name="Submit2" value="Borrar">
</label>
</p>
</form>
</blockquote>
Enviar.php
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style><?php
include("connect.php"); # Incluimos el conectar.php
if(isset($_POST['ok'])) { # Miramos si han dado al boton enviar noticia
$sql = "INSERT INTO `mensajes` (autor,mensaje) values"; # Abirmos la tabla sql
$sql.= "('".$_POST['autor']."','".$_POST['mensaje']."')"; # Y insertamos estos valores
if(mysql_query($sql)) { # Expones sql
echo "Se ha enviado la noticia correctamente"; # si se ha enviado la noticia correctamente
}else{
echo "Ha habido un error en enviar la noticia"; # Si ha habido un error
}
}
echo '<br><a href="ver.php">Ver Noticias</a>'; # IR a la url de ver las noticias
?>
este es el error que hay en Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\AppServ\www\admin\ver.php on line 19
Ver.php
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style><?php
include("connect.php"); # Incluimos el conectar.php para conectarnos a nuestra base de datos
$the = mysql_query("SELECT * from `noticia` ORDER BY `id` DESC"); # Buscamos las noticias almacenadas de la primera a la ultima
if (mysql_num_rows($the)) {
while ($ver = mysql_fetch_array($the)) { # Extramos datos de la tabla sql a la raiz
echo "<br><b>Titulo</b>: '.$ver['titulo'].'"; # Mostramos el titulo de la noticia
echo "<br><b>Mensaje</b>: '.$ver['mensaje'].'"; # Mostramos el Mensaje de la noticia
echo "<br><b>Autor</b>: '.$ver['autor'].'"; # Mostramos el Autor de la noticia
echo "<br><b>Fecha</b>: '.$ver['fecha'].'"; #Mostramos la Fecha de la Noticia
}
} else {
echo "No hay noticias actualmente"; # Si hay 0 noticias, se mostrara esto...
}
echo '<br><a href="enviar.php">Enviar noticias</a>'; # Ir al enviador de noticias
?>
Connect.php
<?php
$db_host="localhost";
$db_nombre="web";
$db_user="root";
$db_pass="root";
$link=mysql_connect($db_host, $db_user, $db_pass) or die ("Error conectando a la base de datos.");
mysql_select_db($db_nombre ,$link) or die("Error seleccionando la base de datos.");
return $link;
?>
Esperos que me Puedan Ayudar amigos