Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

webdesign

erro na linha 1

Recommended Posts

tenho este codigo na minha pagina

 

 

<div id="page_content">

<div id="sidebar">
<?php include"sidebars/sidebar.php";?>
</div><!--sidebar-->

  <div id="page">
<?php

$topico = $_GET['topico'];

$noticias = mysql_query("SELECT
					thumb,
					titulo,
					texto,
					categoria,
					`data`,
					autor,
					valor_real,
					valor_pagseguro,
					visitas
					FROM up_posts
					WHERE titulo = '$topico'")
       	or die(mysql_error());
if(@mysql_num_rows($noticias) <= '0'){
  echo "$info_not";	
}else{

$numero = '0';

	while($res_noticias=mysql_fetch_array($noticias)){

	$thumb = $res_noticias[0];
	$titulo = $res_noticias[1];
	$texto = $res_noticias[2];
	$categoria = $res_noticias[3];
	$data = $res_noticias[4];
	$autor = $res_noticias[5];
	$valor_real = $res_noticias[6];
	$valor_pagseguro = $res_noticias[7];
	$visitas = $res_noticias[8];
	$numero++;

$add_visita = $visitas + 1;
$up_visitas = mysql_query("UPDATE up_posts SET visitas = '$add_visita', data = '$data' WHERE titulo = '$topico'")
          	or die(mysql_error());


 $pega_autor = mysql_query("SELECT nome FROM up_users WHERE id = '$autor'")
              	or die(mysql_error());
 if(@mysql_num_rows($pega_autor) <= '0') echo 'Erro ao selecionar o usuario';
 else{

	 while($res_autor=mysql_fetch_array($pega_autor)){

		 $autor_do_post = $res_autor[0];

?>

	<h1><?php echo $titulo;?></h1>
<script type="text/javascript"><!--
google_ad_client = "pub-3505393501368142";
/* 728x90, criado 17-10-2011 */
google_ad_slot = "1298027856";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
	<span class="info">Data: <?php echo date('d/m/Y - H:m', strtotime($data)); ?> | Autor: <?php echo $autor_do_post; ?> | Categoria: <?php echo $categoria; ?> | Visitas: <?php echo $visitas; ?></span>

<a href="uploads/<?php echo $categoria; ?>/<?php echo $thumb; ?>" rel="shadowbox">
<img src="uploads/<?php echo $categoria; ?>/<?php echo $thumb; ?>" class="alinright" alt="<?php echo $titulo; ?>" width="200" title="<?php echo $titulo; ?>"/>
</a>








	<?php echo $texto;?>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-3505393501368142";
/* FilmesAnimados_banner */
google_ad_slot = "4154170126";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<?php

$conn = mysql_connect('mysql1.000webhost.com', 'a1012737_joel', '') or die(mysql_error());
mysql_select_db('a1012737_joel', $conn) or die(mysql_error());

$sql = "SELECT * FROM up_posts";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){
   	echo $row['nome'],'<br />';
   	echo $row['id'];
   	echo '<br /><a href="ler.php?id='.$row['id'].'">Visualizar</a>';
}
mysql_free_result($result);

?>
<?php

   	$tabela = 'up_posts';
   	$sql = "SELECT * FROM `$tabela` WHERE id = " . $_GET['id']; //get id e o ID da noticia principal
   	$result = mysql_query($sql) or die(mysql_error());
   	while ($row = mysql_fetch_assoc($result)) {

       	echo '<h1>', $row['nome'], '</h1>';
       	echo $row['id'];
   	}
   	unset($result, $row);

   	$tabela = 'comentario';
   	$sql = "SELECT * FROM `$tabela` WHERE idNoticia = " . $_GET['id'];
   	$result = mysql_query($sql) or die(mysql_error());
   	?>
   	<div style="background-color: greenyellow"><h2>Comentarios</h2>
       	<?php
       	while ($row = mysql_fetch_assoc($result)) {

           	echo '<span style="background-color: #FFF; margin:50px;">', $row['texto'], '</span><br /><br />';
       	}
       	?>

<?php
if (isset($_POST['texto'])) {

$texto = $_POST['texto'];
$idNot = $_POST['id']; // vindo do campo hidden
$insert = mysql_query(
       	"INSERT INTO comentario (idNoticia, texto)VALUES ($idNot, '$texto')");

if($insert)
   	echo '<script>alert("Sucesso no cadastro");</script>';
else
     	echo '<script>alert("O comentario nao pode ser inserido!");</script>'; 
}
?>

<h2>Adicionar comentario</h2>
        	<form name="form1" action="" method="POST">
       	<label>Sua MEnsagem</label>
       	<textarea name="texto" rows="4" cols="20">
       	</textarea>
       	<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>" />
       	<input type="submit" value="Enviar" />
       	</form>

<?php mysql_free_result($result); ?>


<?php if($categoria == 'Noticias'){
?>


<?php
}else{
}
?>

<?php
}
}
?>
<?php
}
}
?>
  </div><!--page-->

</div><!--page_content-->

 

mas esse erro só dá quando coloco

 

este codigo

<?php

   	$tabela = 'up_posts';
   	$sql = "SELECT * FROM `$tabela` WHERE id = " . $_GET['id']; //get id e o ID da noticia principal
   	$result = mysql_query($sql, $conn) or die(mysql_error());
   	while ($row = mysql_fetch_assoc($result)) {

       	echo '<h1>', $row['nome'], '</h1>';
       	echo $row['id'];
   	}
   	unset($result, $row);

   	$tabela = 'comentario';
   	$sql = "SELECT * FROM `$tabela` WHERE idNoticia = " . $_GET['id'];
   	$result = mysql_query($sql, $conn) or die(mysql_error());
   	?>
   	<div style="background-color: greenyellow"><h2>Comentarios</h2>
       	<?php
       	while ($row = mysql_fetch_assoc($result)) {

           	echo '<span style="background-color: #FFF; margin:50px;">', $row['texto'], '</span><br /><br />';
       	}
       	?>

 

o que terei errado

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente trocar essa linha

echo '<h1>', $row['nome'], '</h1>';

por essa

echo '<h1>'. $row['nome']. '</h1>';

 

 

e

echo '<span style="background-color: #FFF; margin:50px;">'. $row['texto']. '</span><br /><br />';

por

echo '<span style="background-color: #FFF; margin:50px;">'. $row['texto']. '</span><br /><br />';

Compartilhar este post


Link para o post
Compartilhar em outros sites

alem da sua modificação ele continua a dar aquele erro, mas eu coloquei tabela com estas aspas e deu este erro na linha 1

 

<?php


   	$tabela = 'up_posts';
   	$sql = "SELECT * FROM '$tabela' WHERE id = " . $_GET['id']; //get id e o ID da noticia principal
   	$result = mysql_query($sql) or die(mysql_error());
   	while ($row = mysql_fetch_array($result)) {

       	echo '<h1>'. $row['nome']. '</h1>';
       	echo $row['id'];
   	}
   	unset($result, $row);

   	$tabela = 'comentario';
   	$sql = "SELECT * FROM '$tabela' WHERE idNoticia = " . $_GET['id'];
   	$result = mysql_query($sql) or die(mysql_error());
   	?>
   	<h2>Comentarios</h2>
       	<?php
       	while ($row = mysql_fetch_assoc($result)) {

           	echo '<span style="background-color: #FFF; margin:50px;">'. $row['texto']. '</span><br /><br />';
       	}
       	?>


<?php

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''up_posts' WHERE id =' at line 1

 

 

nao sei qual as aspas que estvam corectas

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente assim:

 $sql = "SELECT * FROM '" . $tabela . "' WHERE id = '" . $_GET['id'] . "'";

 

com esse codigo dá me este erro

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''up_posts' WHERE id = ''' at line 1

nao entend

depois dissu já nem le o codigo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tem certeza que está enviando a $_GET['id'];?

 

 

single.php?id=1212

 

esssa certeza nao tenho tenho noticias.php como faço o get é ai que ele faz o get

<?php
include_once 'conn.php';


$tabela ='up_posts';
$sql	= "SELECT * FROM `$tabela`";
$result = mysql_query($sql, $conn)or die( mysql_error());
while ($row = mysql_fetch_assoc($result)){

echo $row['nome'],'<br />';
echo $row['id'];
echo '<br /><a href="ler.php?id='.$row['id'].'">Visualizar</a>';
}
mysql_free_result($result);

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faça uma verificação se ela existe ou não...

 

if(isset($_GET['id'])){

 

executa o codigo

}else{

Mensagem de erro

}

eu fiz assim mas nao está a postar nada

$tabela = 'up_posts';
		$sql = "SELECT * FROM '" . $tabela . "' WHERE id = '" . $_GET['id'] . "'"; //get id e o ID da noticia principal
     if(isset($_GET['id'])){echo "nao está dando";
     }
   	$result = mysql_query($sql) or die(mysql_error());
   	while ($row = mysql_fetch_array($result)) {

       	echo '<h1>'. $row['nome']. '</h1>';
       	echo $row['id'];
   	}
   	unset($result, $row);

ainda ando aprender php começei agora o curso por issu a minha dificuldade

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim não cara, Tenta assim:

 

if(!isset($_GET['id'])){
echo "nao está dando - Faltando a variavel id";
exit();  
}else{
$id = $_GET['id'];
echo "Variavel id foi enviada!";
}
$result = mysql_query("SELECT * FROM up_posts WHERE id = '$id'")or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<h1>'. $row['nome']. '</h1>';
echo $row['id'];
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Assim não cara, Tenta assim:

 

if(!isset($_GET['id'])){
echo "nao está dando - Faltando a variavel id";
exit();  
}else{
$id = $_GET['id'];
echo "Variavel id foi enviada!";
}
$result = mysql_query("SELECT * FROM up_posts WHERE id = '$id'")or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<h1>'. $row['nome']. '</h1>';
echo $row['id'];
}

deu erro"

nao está dando - Faltando a variavel id"

onde tenho que colocar essa variavel

 

 

mas agora vi que tinha um get topico

ai ele já vai buscar pelo nome

mas dá me este erro

You have an error in your SQL syntax; check the manual that corresponds  to your MySQL server version for the right syntax to use near  ''up_posts' WHERE id = 'A Invenção de Hugo'' at line 1

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.