Page 1 of 1

PHP help:blogs

PostPosted: Sat Mar 26, 2005 4:59 pm
by twinklebrite271
I'm extremely new to PHP, and so I've been using a tutorial to learn how to code my own blog. I've successfully created my database and table and can submit entries to my blog, but I can't display them....
Here's my code:
<?php

mysql_connect ('******', '*****', '****') ;
mysql_select_db ('PHPdatabase');

$sql = "SELECT * FROM php_blog WHERE id=$id";

$result = mysql_query($sql) or
print ("Can't select entries from table php_blog.
" . $sql . "
" . mysql_error());

while ($row = mysql_fetch_array($result))
{
$date = date("l F d Y",$row["timestamp"]);
$title = $row["title"];
$entry = $row["entry"];

print "<b>$title</b>

";
print "$entry

";
print "posted on $date

";
}

?>



When I save and open the page, this is all it says:

" . $sql . "
" . mysql_error()); while ($row = mysql_fetch_array($result)) { $date = date("l F d Y",$row["timestamp"]); $title = $row["title"]; $entry = $row["entry"]; print "$title
\"; print "$entry
\"; print "posted on $date
\"; } ?>


Can someone tell me what I'm doing wrong or suggest an alternate method of making a blog for my website? That would be much appreciated ^_^

PostPosted: Sat Mar 26, 2005 8:43 pm
by LorentzForce
Replace 'print' with 'echo'. Oh, and for good measure, just in case, remove that space before ; in the first line of actual code.

PostPosted: Sat Mar 26, 2005 9:26 pm
by Kireihana
:eh: You are a braver person than I.

PostPosted: Sat Mar 26, 2005 10:10 pm
by LorentzForce
And to ease your life of coding, here's how the code should look like. I think.

Code: Select all
<?php

mysql_connect ('******', '*****', '****');
mysql_select_db ('PHPdatabase');

$sql = "SELECT * FROM php_blog WHERE id=$id";

$result = mysql_query($sql) or
echo "Can't select entries from table php_blog.
".$sql."
".mysql_error();

while ($row = mysql_fetch_array($result)) {
  $date = date("l F d Y",$row["timestamp"]);
  $title = $row["title"];
  $entry = $row["entry"];

  echo "<b>$title</b>

";
  echo "$entry

";
  echo "posted on $date

";
}

?>


Remember to indent your code to make it look neat!

[edit] I can't spell.

PostPosted: Sun Mar 27, 2005 2:09 pm
by twinklebrite271
Yay! It works! Thank you for your help!