Page 1 of 1
blog tutorial need help/part05
Posted: Mon Jan 30, 2012 11:58 pm
by hellboj
after i do the page blog_list.php a i go and test the page i get this warning:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/blog/core/inc/comments.inc.php on line 17
<?php
//puščaš vse objave ki so dane v blogu.
function get_comments($pid) {
$pid = (int)$pid;
$sql = "SELECT
`comment_body` AS `body`,
`comment_user` AS `user`,
DATE_FORMAT(`comment_date`, '%d/%m/%Y %H:%i:%s') AS `date`
FROM `comments`
WHERE `post_id` = {pid}";
$comments = mysql_query($sql);
$return = array();
while (($row =mysql_fetch_assoc($comments)) !== false) {
$return[] = $row;
}
return $return;
}
//dodaj komentar
function add_comments($pid, $user, $body) {
if (valid_pid($pid) === fales) {
return false;
}
$pid = (int)$pid;
$user = mysql_real_escape_string(htmlentites($user));
$body = mysql_real_escape_string(nl2br(htmlentites($body)));
mysql_query("INSERT INTO `comments` (`post_id`, `comment_user`, `comment_body`, `comment_date`) VALUES ({$pid}, '{$user}', '{$body}', NOW())");
return true;
}
?>
Re: blog tutorial need help/part05
Posted: Tue Jan 31, 2012 12:15 am
by Temor
you missed a $ before the $pid variable in your sql query.
Re: blog tutorial need help/part05
Posted: Tue Jan 31, 2012 8:31 pm
by hellboj
Temor wrote:you missed a $ before the $pid variable in your sql query.
Thank you 1000 times...
Re: blog tutorial need help/part05
Posted: Tue Jan 31, 2012 9:48 pm
by hellboj
hellboj wrote:Temor wrote:you missed a $ before the $pid variable in your sql query.
Thank you 1000 times...
what i missed here? i really suks... not my days---
<?php
foreach ($post['comments'] as comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
Re: blog tutorial need help/part05
Posted: Tue Jan 31, 2012 9:50 pm
by hellboj
hellboj wrote:hellboj wrote:Temor wrote:you missed a $ before the $pid variable in your sql query.
Thank you 1000 times...
what i missed here? i really suks... not my days---
<?php
foreach ($post['comments'] as comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
i get error:
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 39
Re: blog tutorial need help/part05
Posted: Tue Jan 31, 2012 9:55 pm
by hellboj
hellboj wrote:hellboj wrote:hellboj wrote:
Thank you 1000 times...
what i missed here? i really suks... not my days---
<?php
foreach ($post['comments'] as comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
i get error:
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 39
uuuu sory finly saw it i miss $ in comment...
blog tutorial need help/part06
Posted: Tue Jan 31, 2012 11:23 pm
by hellboj
can you help me?
error:
Fatal error: Call to undefined function add_comment() in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 6
blog_read.php
<?php
<?php
include('core/init.inc.php');
if (isset($_GET['pid'], $_POST['user'], $_POST['body'])){
if (add_comment($_GET['pid'], $_POST['user'], $_POST['body'])){
header("Location: blog_read.php?pid={$_GET['pid']}");
}else{
header('Location: blog_list.php');
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="windows-1250">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="utf-8">
<title>Polna Pljuca Blog</title>
</head>
<body>
<div align="center">
<h1>Zapiši idejo</h1>
<h2>let's word talks...</h2>
<?php
if (isset($_GET['pid']) === false || valid_pid($_GET['pid']) === false){
echo 'Invalid post ID.';
}else{
$post = get_post($_GET['pid']);
?>
<h2><?php echo $post['title']; ?></h2>
<h4>Od <?php echo $post['user']; ?> ob <?php echo $post['date']; ?> (<?php echo count($post['comments']); ?> comments)</h4>
<hr />
<p><?php echo $post['body']; ?></p>
<hr />
<?php
foreach ($post['comments'] as $comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
<form action="" method="post">
<p>
<label for="user">Ime:</label>
<input type="text" name="user" id="user" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Dodaj komentar" />
</p>
</form>
<?php
}
?>
</div>
</body>
</html>
Re: blog tutorial need help/part06
Posted: Tue Jan 31, 2012 11:42 pm
by hellboj
hellboj wrote:can you help me?
error:
Fatal error: Call to undefined function add_comment() in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 6
blog_read.php
<?php
<?php
include('core/init.inc.php');
if (isset($_GET['pid'], $_POST['user'], $_POST['body'])){
if (add_comment($_GET['pid'], $_POST['user'], $_POST['body'])){
header("Location: blog_read.php?pid={$_GET['pid']}");
}else{
header('Location: blog_list.php');
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="windows-1250">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="utf-8">
<title>Polna Pljuca Blog</title>
</head>
<body>
<div align="center">
<h1>Zapiši idejo</h1>
<h2>let's word talks...</h2>
<?php
if (isset($_GET['pid']) === false || valid_pid($_GET['pid']) === false){
echo 'Invalid post ID.';
}else{
$post = get_post($_GET['pid']);
?>
<h2><?php echo $post['title']; ?></h2>
<h4>Od <?php echo $post['user']; ?> ob <?php echo $post['date']; ?> (<?php echo count($post['comments']); ?> comments)</h4>
<hr />
<p><?php echo $post['body']; ?></p>
<hr />
<?php
foreach ($post['comments'] as $comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
<form action="" method="post">
<p>
<label for="user">Ime:</label>
<input type="text" name="user" id="user" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Dodaj komentar" />
</p>
</form>
<?php
}
?>
</div>
</body>
</html>
may be is something wrong in
comments.inc.php
<?php
//puščaš vse objave ki so dane v blogu.
function get_comments($pid){
$pid = (int)$pid;
$sql = "SELECT
`comment_body` AS `body`,
`comment_user` AS `user`,
DATE_FORMAT(`comment_date`, '%d/%m/%Y %H:%i:%s') AS `date`
FROM `comments`
WHERE `post_id` = {$pid}";
$comments = mysql_query($sql);
$return = array();
while (($row =mysql_fetch_assoc($comments)) !== false) {
$return[] = $row;
}
return $return;
}
//dodaj komentar
function add_comments($pid, $user, $body) {
if (valid_pid($pid) === fales) {
return false;
}
$pid = (int)$pid;
$user = mysql_real_escape_string(htmlentities($user));
$body = mysql_real_escape_string(nl2br(htmlentities($body)));
mysql_query("INSERT INTO `comments` (`post_id`, `comment_user`, `comment_body`, `comment_date`) VALUES ({$pid}, '{$user}', '{$body}', NOW())");
return true;
}
?>
Re: blog tutorial need help/part06
Posted: Tue Jan 31, 2012 11:56 pm
by hellboj
hellboj wrote:hellboj wrote:can you help me?
error:
Fatal error: Call to undefined function add_comment() in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 6
blog_read.php
<?php
<?php
include('core/init.inc.php');
if (isset($_GET['pid'], $_POST['user'], $_POST['body'])){
if (add_comment($_GET['pid'], $_POST['user'], $_POST['body'])){
header("Location: blog_read.php?pid={$_GET['pid']}");
}else{
header('Location: blog_list.php');
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="windows-1250">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="utf-8">
<title>Polna Pljuca Blog</title>
</head>
<body>
<div align="center">
<h1>Zapiši idejo</h1>
<h2>let's word talks...</h2>
<?php
if (isset($_GET['pid']) === false || valid_pid($_GET['pid']) === false){
echo 'Invalid post ID.';
}else{
$post = get_post($_GET['pid']);
?>
<h2><?php echo $post['title']; ?></h2>
<h4>Od <?php echo $post['user']; ?> ob <?php echo $post['date']; ?> (<?php echo count($post['comments']); ?> comments)</h4>
<hr />
<p><?php echo $post['body']; ?></p>
<hr />
<?php
foreach ($post['comments'] as $comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
<form action="" method="post">
<p>
<label for="user">Ime:</label>
<input type="text" name="user" id="user" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Dodaj komentar" />
</p>
</form>
<?php
}
?>
</div>
</body>
</html>
may be is something wrong in
comments.inc.php
<?php
//puščaš vse objave ki so dane v blogu.
function get_comments($pid){
$pid = (int)$pid;
$sql = "SELECT
`comment_body` AS `body`,
`comment_user` AS `user`,
DATE_FORMAT(`comment_date`, '%d/%m/%Y %H:%i:%s') AS `date`
FROM `comments`
WHERE `post_id` = {$pid}";
$comments = mysql_query($sql);
$return = array();
while (($row =mysql_fetch_assoc($comments)) !== false) {
$return[] = $row;
}
return $return;
}
//dodaj komentar
function add_comments($pid, $user, $body) {
if (valid_pid($pid) === fales) {
return false;
}
$pid = (int)$pid;
$user = mysql_real_escape_string(htmlentities($user));
$body = mysql_real_escape_string(nl2br(htmlentities($body)));
mysql_query("INSERT INTO `comments` (`post_id`, `comment_user`, `comment_body`, `comment_date`) VALUES ({$pid}, '{$user}', '{$body}', NOW())");
return true;
}
?>
i fix erorr
Fatal error: Call to undefined function add_comment() in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 6
and get new one
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php:1) in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 7
i lost and don't now what to fix....help pleas
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 12:05 am
by Temor
Fatal error: Call to undefined function add_comment() in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 6
That means you failed to include comments.inc.php. Are you including it in init.inc.php?
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php:1) in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 7
<?php
<?php
this won't work. it doesn't make sense to open a new php block without closing the previous one.
Remove the second <?php tag and it should work.
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 12:14 am
by hellboj
this won't work. it doesn't make sense to open a new php block without closing the previous one.
Remove the second <?php tag and it should work.[/quote]
i remove <?php and still not working...
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 12:16 am
by hellboj
hellboj wrote:this won't work. it doesn't make sense to open a new php block without closing the previous one.
Remove the second <?php tag and it should work.
i remove <?php and still not working...[/quote]
the same error
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php:1) in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 7
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 12:23 am
by hellboj
hellboj wrote:hellboj wrote:this won't work. it doesn't make sense to open a new php block without closing the previous one.
Remove the second <?php tag and it should work.
i remove <?php and still not working...
the same error
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php:1) in /Applications/XAMPP/xamppfiles/htdocs/blog/blog_read.php on line 7[/quote]
<?php
include('core/init.inc.php');
if (isset($_GET['pid'], $_POST['user'], $_POST['body'])){
if (add_comments($_GET['pid'], $_POST['user'], $_POST['body'])){
header("Location: blog_read.php?pid={$_GET['pid']}");
}else{
header('Location: blog_list.php');
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="windows-1250">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="utf-8">
<title>Polna Pljuca Blog</title>
</head>
<body>
<div align="center">
<h1>Zapiši idejo</h1>
<h2>let's word talks...</h2>
<?php
if (isset($_GET['pid']) === false || valid_pid($_GET['pid']) === false){
echo 'Invalid post ID.';
}else{
$post = get_post($_GET['pid']);
?>
<h2><?php echo $post['title']; ?></h2>
<h4>Od <?php echo $post['user']; ?> ob <?php echo $post['date']; ?> (<?php echo count($post['comments']); ?> comments)</h4>
<hr />
<p><?php echo $post['body']; ?></p>
<hr />
<?php
foreach ($post['comments'] as $comment) {
?>
<h4>Od<?php echo $comment['user']; ?> ustvarjeno <?php echo $comment['date']; ?></h4>
<p><?php echo $comment['body']; ?></p>
<hr />
<?php
}
?>
<form action="" method="post">
<p>
<label for="user">Ime:</label>
<input type="text" name="user" id="user" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Dodaj komentar" />
</p>
</form>
<?php
}
?>
</div>
</body>
</html>
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 1:00 am
by hellboj
and this is my
post.inc.php
<?php
// preveri če je post id v tabli.
function valid_pid($pid) {
$pid = (int)$pid;
$total = mysql_query("SELECT COUNT(`post_id`) FROM `posts` WHERE `post_id` = {$pid}");
$total = mysql_result($total, 0);
if ($total != 1){
return false;
}else {
return true;
}
}
//puščati povzetek of vseh blog objav.
function get_posts(){
$sql =
"SELECT
`posts`.`post_id` AS `id`,
`posts`.`post_title` AS `title`,
LEFT(`posts`.`post_body`, 512) AS `preview`,
`posts`.`post_user` AS `user`,
DATE_FORMAT(`posts`.`post_date`,'%d/%m/%Y %H:%i:%s') AS `date`,
`comments`.`total_comments`,
DATE_FORMAT(`comments`.`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment`
FROM `posts`
LEFT JOIN (
SELECT
`post_id`,
COUNT(`comment_id`) AS `total_comments`,
MAX(`comment_date`) AS `last_comment`
FROM `comments`
GROUP BY `post_id`
) AS `comments`
ON `posts`.`post_id` = `comments`.`post_id`
ORDER BY `posts`.`post_date` DESC";
$posts = mysql_query($sql);
$rows = array();
while (($row = mysql_fetch_assoc($posts)) !== false){
$rows[] = array(
'id' => $row['id'],
'title' => $row['title'],
'preview' => $row['preview'],
'user' => $row['user'],
'date' => $row['date'],
'total_comments' => ($row['total_comments'] === null) ? 0 : $row['total_comments'],
'last_comment' => ($row['last_comment'] === null) ? 'never' : $row['last_comment']
);
}
return $rows;
}
//puščati enojni post iz table
function get_post($pid) {
$pid = (int)$pid;
$sql = "SELECT
`post_title` AS `title`,
`post_body` AS `body`,
`post_user` AS `user`,
`post_date` AS `date`
FROM `posts`
WHERE `post_id` = {$pid}";
$post = mysql_query($sql);
$post = mysql_fetch_assoc($post);
$post['comments'] = get_comments($pid);
return $post;
}
//dodajaš nov blog objava
function add_post($name, $title, $body) {
$name = mysql_real_escape_string(htmlentities($name));
$title = mysql_real_escape_string(htmlentities($title));
$body = mysql_real_escape_string(nl2br(htmlentities($body)));
mysql_query("INSERT INTO 'posts' ('post_user', 'post_title', 'post_body', 'post_date') VALUES ('{$name}', '{$title}', '{$body}', NOW())");
}
?>
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 1:03 am
by hellboj
hellboj wrote:and this is my
post.inc.php
<?php
// preveri če je post id v tabli.
function valid_pid($pid) {
$pid = (int)$pid;
$total = mysql_query("SELECT COUNT(`post_id`) FROM `posts` WHERE `post_id` = {$pid}");
$total = mysql_result($total, 0);
if ($total != 1){
return false;
}else {
return true;
}
}
//puščati povzetek of vseh blog objav.
function get_posts(){
$sql =
"SELECT
`posts`.`post_id` AS `id`,
`posts`.`post_title` AS `title`,
LEFT(`posts`.`post_body`, 512) AS `preview`,
`posts`.`post_user` AS `user`,
DATE_FORMAT(`posts`.`post_date`,'%d/%m/%Y %H:%i:%s') AS `date`,
`comments`.`total_comments`,
DATE_FORMAT(`comments`.`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment`
FROM `posts`
LEFT JOIN (
SELECT
`post_id`,
COUNT(`comment_id`) AS `total_comments`,
MAX(`comment_date`) AS `last_comment`
FROM `comments`
GROUP BY `post_id`
) AS `comments`
ON `posts`.`post_id` = `comments`.`post_id`
ORDER BY `posts`.`post_date` DESC";
$posts = mysql_query($sql);
$rows = array();
while (($row = mysql_fetch_assoc($posts)) !== false){
$rows[] = array(
'id' => $row['id'],
'title' => $row['title'],
'preview' => $row['preview'],
'user' => $row['user'],
'date' => $row['date'],
'total_comments' => ($row['total_comments'] === null) ? 0 : $row['total_comments'],
'last_comment' => ($row['last_comment'] === null) ? 'never' : $row['last_comment']
);
}
return $rows;
}
//puščati enojni post iz table
function get_post($pid) {
$pid = (int)$pid;
$sql = "SELECT
`post_title` AS `title`,
`post_body` AS `body`,
`post_user` AS `user`,
`post_date` AS `date`
FROM `posts`
WHERE `post_id` = {$pid}";
$post = mysql_query($sql);
$post = mysql_fetch_assoc($post);
$post['comments'] = get_comments($pid);
return $post;
}
//dodajaš nov blog objava
function add_post($name, $title, $body) {
$name = mysql_real_escape_string(htmlentities($name));
$title = mysql_real_escape_string(htmlentities($title));
$body = mysql_real_escape_string(nl2br(htmlentities($body)));
mysql_query("INSERT INTO 'posts' ('post_user', 'post_title', 'post_body', 'post_date') VALUES ('{$name}', '{$title}', '{$body}', NOW())");
}
?>
when i post i comment come error:
in browser root:
http://localhost/blog/blog_read.php?pid=1 i relly don't now where is problem in blog_read.php,tnx for helping me ....
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 6:09 pm
by Temor
You're gonna have to be patient. Stop spamming. I'm doing this on my spare time while having a job and studying.
Re: blog tutorial need help/part05
Posted: Wed Feb 01, 2012 11:40 pm
by hellboj
Temor wrote:You're gonna have to be patient. Stop spamming. I'm doing this on my spare time while having a job and studying.
No problem, i find a solution i add
top of page <?ob_start();?> and end of the page <?ob_flush();?>
tnx and i hope you not angry,super tutorial.