Inserir.php
Neste arquivo eu queria colocar o campo pra upload da imagem, um detalhe é que ele nao usa nenhum outro arquivo pra adicionar as informações ou seja é nele mesmo q tem as funções.
<?php require_once('../Connections/Noticias.php'); ?>
<?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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO noticias (titulo, texto, clicks) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['titulo'], "text"),
GetSQLValueString($HTTP_POST_VARS['texto'], "text"),
GetSQLValueString($HTTP_POST_VARS['clicks'], "int"));
mysql_select_db($database_Noticias, $Noticias);
$Result1 = mysql_query($insertSQL, $Noticias) or die(mysql_error());
}
?>
<html>
<head>
<title>Documento sem título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Titulo:</td>
<td><input type="text" name="titulo" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Texto:</td>
<td>
<textarea name="texto" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Clicks:</td>
<td><input type="text" name="clicks" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><div align="right">
<input type="submit" value="Inserir notícia">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
listar.php
Este aqui lista as manchetes ou seja os titulos das noticias, este nao ha necessidade de mudar nada, mas vou colocar pra alguem quiser aproveitar:
<?php require_once('../Connections/Noticias.php'); ?>
<?php
mysql_select_db($database_Noticias, $Noticias);
$query_listar_noticias = "SELECT * FROM noticias";
$listar_noticias = mysql_query($query_listar_noticias, $Noticias) or die(mysql_error());
$row_listar_noticias = mysql_fetch_assoc($listar_noticias);
$totalRows_listar_noticias = mysql_num_rows($listar_noticias);
?>
<html>
<head>
<title>Documento sem título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php do { ?>
<font size="2" face="Trebuchet MS">Titulo: <strong><?php echo $row_listar_noticias['titulo']; ?><br>
</strong>Clicks: <strong><?php echo $row_listar_noticias['clicks']; ?></strong><br>
<a href="exibir.php?id=<?php echo $row_listar_noticias['id']; ?>">Leia Mais +</a><br>
</font>
<hr width="100%" size="1" noshade>
<font size="2" face="Trebuchet MS"><br>
</font>
<?php } while ($row_listar_noticias = mysql_fetch_assoc($listar_noticias)); ?>
</body>
</html>
<?php
mysql_free_result($listar_noticias);
?>
exibir.php
É e neste arquivo eu queria q aparecesse a imagem q cadastrei no inicio juntamente com as informacoes da noticia:
<?php require_once('../Connections/Noticias.php'); ?>
<?php
$colname_exibir = "1";
if (isset($HTTP_GET_VARS['id'])) {
$colname_exibir = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['id'] : addslashes($HTTP_GET_VARS['id']);
}
mysql_select_db($database_Noticias, $Noticias);
$query_exibir = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_exibir);
$exibir = mysql_query($query_exibir, $Noticias) or die(mysql_error());
$row_exibir = mysql_fetch_assoc($exibir);
$totalRows_exibir = mysql_num_rows($exibir);
mysql_query("UPDATE noticias set clicks=clicks+1 where id='$_GET[id]'");
?>
<html>
<head>
<title>Documento sem título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<font size="2" face="Trebuchet MS"><strong>Titulo: </strong><?php echo $row_exibir['titulo']; ?><br>
<strong>Clicks:</strong> <?php echo $row_exibir['clicks']; ?><br>
<br>
<?php echo $row_exibir['texto']; ?></font>
</body>
</html>
<?php
mysql_free_result($exibir);
?>
Agora o sql da tabela:
CREATE TABLE `Noticias` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`titulo` VARCHAR(255),
`texto` TEXT,
`clicks` INT DEFAULT "0" NOT NULL
) TYPE = MYISAM
COMMENT = "tutorial";
Este script eu peguei de um artigo que foi postado por João Vagner no site do iMasters, caso alguém quer vê-lo Clique aqui (direitos autorais né).
Aguardo ajuda, obrigado.