csilva
-
Total de itens
7 -
Registro em
-
Última visita
Posts postados por csilva
-
-
Amigos, estou usando essa SQL para buscar textos mais lido da semana, mas não retorna resultado algum. Será que alguém poderia dar uma luz? É uma emergência, para um trabalho. Obrigado.
<?php $sql = "SELECT SQL_CACHE * FROM artigos WHERE (YEAR(data) = YEAR(now())) and (MONTH(data) = MONTH(now())) and (WEEK(data) = WEEK(NOW())) ORDER BY visitas DESC LIMIT 10"; $query = mysql_query($sql); while($dados = mysql_fetch_array($query, MYSQL_ASSOC)) { $dados['id']; $dados['autor']; $dados['data']; $dados['titulo']; $dados['visitas']; ?> <?php echo $dados['autor']; ?> - <?php echo $dados['titulo']; ?> - <?php echo $dados['visitas']; ?> <?php } />
-
Acrescente essa linha em depois de inserir su noticia, lembrando que no seu codigo não vi nenhuma variavel dessas que coloquei $noticia, $fotos, $mp3, $midias, até mais
$incrementar=mysql_query("insert into categorias (noticia, fotos, mp3, midias) values ('$noticia','$fotos','$mp3','$midias')") or die("Falha ao tentar incrementar noticia: ".mysql_error());
Amigo, obrigado por tentar ajudar, mas não deu certo,
com certeza, porque meu texto não foi claro
e você não o entendeu.
Explico de novo, abaixo:
Os posts são registrados na tabela NOTICIAS, que tem os campos nome, data, categoria, resumo e notas
Preciso - e não consigo - indicar o acréscito de cada um desses posts na tabela CATEGORIAS, que tem como os campos: nome_categoria e numero_artigo.
Em nome_categoria criei as categorias Notícias, Fotos, MP3 e MÍdis e quero contar a quantidade de posts existentes em cada uma delas, com os números aparecendo em numero_artigo.
-
Amigos,
Publico texto com esse script na tabela notícias. Agora, preciso incrementar cada publicação na tabela CATEGORIAS. Como sou novato, estou arrancando os cabelos, e nada...!
A tabela CATEGORIAS tem os campos nome_categoria e numero-artigo, além de id, claro. As categorias cadastradas no DB são 1. Notícias, 2. Fotos, 3. MP3 e 4. Mídis.
Será que alguém poderia me ajudar?
.........
<?php
session_start();
if (isset($_POST['enviar'])) {
$nome = $_POST['nome'];
$data = date("Y-m-d - H:i:s");
$categoria = $_POST['categoria'];
$resumo = $_POST['resumo'];
$notas = $_POST['notas'];
if($nome == ''){
echo "Preencha nome";
}elseif($notas == ''){
echo "Preencha notas";
}elseif($categoria == ''){
echo "Marque uma categoria";
}else{
$inserir = mysql_query("INSERT INTO noticias (nome, data, categoria, resumo, notas) VALUES ('$nome','$data','$categoria','$resumo','$notas')");
$post_id = mysql_insert_id();
if($inserir =='') {
echo mysql_error();;
}else {
echo "Publicado com sucesso";
}
}
}
?>
-
Olá, amigos.
Alguém poderia me ajudar? Tenho esse arquivo de upload e não consigo imprimor o nome do arquivo ($filename). Nos meus esforços, de quem é iniciante em PHP, somente congui o arquivo tmp ($tmpFile). O script envia arquivos para o Dropbox. Obrigado.
...........................................
<?php
$passw = "xxxxxxx"; //change this to a password of your choice.
if ($_POST) {
require 'DropboxUploader.php';
try {
// Rename uploaded file to reflect original name
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
$tmpDir = uniqid('/tmp/DropboxUploader-');
if (!mkdir($tmpDir))
throw new Exception('Cannot create temporary directory!');
if ($_FILES['file']['name'] === "")
throw new Exception('File name not supplied by the browser.');
$tmpFile = $tmpDir.'/'.str_replace("/", '_', $_FILES['file']['name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmpFile))
throw new Exception('Cannot rename uploaded file!');
if ($_POST['txtPassword'] != $passw)
throw new Exception('Wrong Password');
// Upload
$uploader = new DropboxUploader(xxx@xxx.net, 'xxxxxx');// enter dropbox credentials
$uploader->upload($tmpFile, $_POST['dest']);
echo '<span style="color: green;font-weight:bold;margin-left:393px;">Enviado com sucesso!</span>';
} catch(Exception $e) {
echo '<span style="color: red;font-weight:bold;margin-left:393px;">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
}
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
if (isset($tmpDir) && file_exists($tmpDir))
rmdir($tmpDir);
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" /><br><br>
<input type="submit" value="Upload the file to my Dropbox!" />
<input style="display:none" type="text" name="dest" value="sua pasta de destino" />
<br/>
<br/>
Password: <input type="password" title="Enter your password" name="txtPassword" />
</form>
.............................
DropboxUploader.php
<?php
/**
* Dropbox Uploader
*
* Copyright © 2009 Jaka Jancar
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Jaka Jancar [jaka@kubje.org] [http://jaka.kubje.org/]
* @version 1.1.5
*/
class DropboxUploader {
protected $email;
protected $password;
protected $caCertSourceType = self::CACERT_SOURCE_SYSTEM;
const CACERT_SOURCE_SYSTEM = 0;
const CACERT_SOURCE_FILE = 1;
const CACERT_SOURCE_DIR = 2;
protected $caCertSource;
protected $loggedIn = false;
protected $cookies = array();
/**
* Constructor
*
* @param string $email
* @param string|null $password
*/
public function __construct($email, $password) {
// Check requirements
if (!extension_loaded('curl'))
throw new Exception('DropboxUploader requires the cURL extension.');
$this->email = $email;
$this->password = $password;
}
public function setCaCertificateFile($file)
{
$this->caCertSourceType = self::CACERT_SOURCE_FILE;
$this->caCertSource = $file;
}
public function setCaCertificateDir($dir)
{
$this->caCertSourceType = self::CACERT_SOURCE_DIR;
$this->caCertSource = $dir;
}
public function upload($filename, $remoteDir='/') {
if (!file_exists($filename) or !is_file($filename) or !is_readable($filename))
throw new Exception("File '$filename' does not exist or is not readable.");
if (!is_string($remoteDir))
throw new Exception("Remote directory must be a string, is ".gettype($remoteDir)." instead.");
if (!$this->loggedIn)
$this->login();
$data = $this->request('https://www.dropbox.com/home');
$token = $this->extractToken($data, 'https://dl-web.dropbox.com/upload');
$data = $this->request('https://dl-web.dropbox.com/upload', true, array('plain'=>'yes', 'file'=>'@'.$filename, 'dest'=>$remoteDir, 't'=>$token));
if (strpos($data, 'HTTP/1.1 302 FOUND') === false)
throw new Exception('Upload failed!');
}
protected function login() {
$data = $this->request('https://www.dropbox.com/login');
$token = $this->extractToken($data, '/login');
$data = $this->request('https://www.dropbox.com/login', true, array('login_email'=>$this->email, 'login_password'=>$this->password, 't'=>$token));
if (stripos($data, 'location: /home') === false)
throw new Exception('Login unsuccessful.');
$this->loggedIn = true;
}
protected function request($url, $post=false, $postData=array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
switch ($this->caCertSourceType) {
case self::CACERT_SOURCE_FILE:
curl_setopt($ch, CURLOPT_CAINFO, $this->caCertSource);
break;
case self::CACERT_SOURCE_DIR:
curl_setopt($ch, CURLOPT_CAPATH, $this->caCertSource);
break;
}
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post) {
curl_setopt($ch, CURLOPT_POST, $post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
// Send cookies
$rawCookies = array();
foreach ($this->cookies as $k=>$v)
$rawCookies[] = "$k=$v";
$rawCookies = implode(';', $rawCookies);
curl_setopt($ch, CURLOPT_COOKIE, $rawCookies);
$data = curl_exec($ch);
if ($data === false)
throw new Exception('Cannot execute request: '.curl_error($ch));
// Store received cookies
preg_match_all('/Set-Cookie: ([^=]+)=(.*?);/i', $data, $matches, PREG_SET_ORDER);
foreach ($matches as $match)
$this->cookies[$match[1]] = $match[2];
curl_close($ch);
return $data;
}
protected function extractToken($html, $formAction) {
if (!preg_match('/<form [^>]*'.preg_quote($formAction, '/').'[^>]*>.*?(<input [^>]*name="t" [^>]*value="(.*?)"[^>]*>).*?<\/form>/is', $html, $matches) || !isset($matches[2]))
throw new Exception("Cannot extract token! (form action=$formAction)");
return $matches[2];
}
}
?>
-
Marcos, funcionou perfeitamente.
Muito obrigado por sua ajuda.
Abração. E muito sucesso!
-
Esse código para publicar no DB só funciona se eu deletar o if(isset...
Por que ocorre esse problema? Qual é a solução? Quem pode me dar uma luz?
<?php
if (isset($_POST['enviar'])) {
$nome = $_POST['nome'];
$notas = $_POST['notas'];
if($nome == ''){
echo "preencha nome";
}elseif($notas == ''){
echo "preencha notas";
}else{
$inserir = mysql_query("INSERT INTO noticias (nome, notas) VALUES ('$nome', '$notas')");
if($inserir =='') {
echo "Erro ao inserir";
}else {
echo "Publicado com sucesso";
}
}
}
?>
<table width="400" border="0" align="center" cellpadding="1" cellspacing="1" class="midias">
<form mane="teste" action="" method="post" enctype="multipart/form-data">
<tr>
<td width="121" class="style2">Nome da Foto</td>
<td width="532"><input type="text" name="nome" /></td>
</tr>
<tr>
<td class="style2">Texto</td>
<td><input type="text" name="notas" /></td>
</tr>
<tr>
<td><input type="submit" nome="enviar" value="Enviar" /></td>
<td>Largura limite: 600 px.<br>
</span><strong>xxxx.</strong></td>
</tr>
</form>
</table>
(Resolvido) SQL para selecionar dados por semana
em MySQL
Postado
Valeu, Denis!
Era isso mesmo!
Funcionando.
Obrigado!