Estoy haciendo un foro en el cual cuando un usuario esta viendo un tema,estoy creando que aparezca un boton me gusta tipo facebook o algo asi jeeje.
Bueno, tengo mi tabla en mysql que es esta:
Código PHP:
CREATE TABLE IF NOT EXISTS `topics` (
`topic_id` int(8) NOT NULL AUTO_INCREMENT,
`topic_subject` varchar(255) NOT NULL,
`topic_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`topic_cat` int(8) NOT NULL,
`topic_by` int(8) NOT NULL,
`topic_likes-users` int(11) NOT NULL,
PRIMARY KEY (`topic_id`),
KEY `topic_cat` (`topic_cat`),
KEY `topic_by` (`topic_by`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
Código PHP:
<?php
include 'include/php/conexion.php';
//Conexion con la Base de Datos
$link=@dbConnect();
if (!$link) {
echo "Error conectando a la Base de Datos.";
}
if ($link =="202") {
echo "Error seleccionando la Base de Datos.";
}
$sql = "SELECT
topic_id,
topic_subject
FROM
topics
WHERE
topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
//Segundo
//obtiene el nombre
$datos = mysql_fetch_row($result);
$title = "$datos[1] | Web";
include_once('./header.php');
$result = mysql_query($sql);
?>
<div id="main">
<div class="content">
<?php
echo '<br />';
$id = $_GET['id'];
$sql = "SELECT
topic_id,
topic_subject
FROM
topics
WHERE
topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'Este tema no existe.';
}
else
{
while($row = mysql_fetch_assoc($result))
{
//muestro el tema
echo '
<a href="#reply">Responder</a><br />
<table class="topic" border="1">
<tr>
<th colspan="2">' . $row['topic_subject'] . '</th>
</tr>';
$posts_sql = "SELECT
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
users.id,
users.username
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['id']);
$posts_result = mysql_query($posts_sql);
if(!$posts_result)
{
echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
}
else
{
while($posts_row = mysql_fetch_assoc($posts_result))
{
echo '<tr class="topic-post">
<td class="user-post">';?><img src="http://www.forosdelweb.com/f18/users/<?php echo "$id"; ?>/pic1.jpg" alt="Ad" ><?php echo '<a href="http://www.forosdelweb.com/f18/profile/?id=' .$posts_row['id'] .'">' . $posts_row['username'] . '</a><br/>' . date('d-m-Y H:i', strtotime($posts_row['post_date'])) . '</td>
<td class="post-content">' . html_entity_decode($posts_row['post_content']) . '</td>
</tr>
';
echo '<tr>
<td><a href="like.php?id='.$row['topic_id'].'" id="east" title="Me gusta"><img src="include/images/buttons/like.jpg"/></a></td>
</tr>';
}
}
if(isset($_SESSION['id']))
{
//show reply box
echo '<div id="reply"><tr><td colspan="2"><h2>Responder:</h2><br />
<form method="post" action="reply.php?id=' . $row['topic_id'] . '">
<textarea name="reply-content"></textarea><br /><br />
<input type="submit" value="Submit reply" />
</form></td></tr></div>';
}
else
{
echo '<tr><td colspan=2>Tienes que <a href="http://www.forosdelweb.com/f18/login.php">inciar sesión</a> para responder. Si sos nuevo <a href="http://www.forosdelweb.com/f18/signup">regístrate</a> gratis.';
}
//fin de la tabla
echo '</table><br /><br />';
}
}
}
?>
</div></div>
<br />
<br />
<?php
include 'include/php/footer.php';
?>
Código PHP:
<?php
include 'include/php/conexion.php';
$title =" Me gusta | Web.com";
include 'header.php';
//Conexion con la Base de Datos
$link=@dbConnect();
if (!$link) {
echo "Error conectando a la Base de Datos.";
}
if ($link =="202") {
echo "Error seleccionando la Base de Datos.";
}
$id = $_GET['id'];
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$id = $_SESSION['id'];
$sql = "INSERT INTO topics (topic_likes-user) VALUES (" . $_SESSION['id'] . ")";
$query = mysql_query($sql);
echo "Este tema te gusta";
}else{
echo "Tienes que iniciar sesión.<br />";
}
?>
Quien pueda ayudarme se los agradezco!