PHP help:blogs

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

PHP help:blogs

Postby twinklebrite271 » Sat Mar 26, 2005 4:59 pm

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 ^_^
Prayer Guardians Thread
CAA Prayer Gaurdians Prayer List
"If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrarily wise, what it would be it wouldn't, and what it wouldn't be, it would." Alice in Wonderland

98% of the teenage population does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this in your signature.
User avatar
twinklebrite271
 
Posts: 25
Joined: Sun Feb 06, 2005 4:07 pm
Location: Middle Earth

Postby LorentzForce » Sat Mar 26, 2005 8:43 pm

Replace 'print' with 'echo'. Oh, and for good measure, just in case, remove that space before ; in the first line of actual code.
Image
User avatar
LorentzForce
 
Posts: 1263
Joined: Sun Jun 01, 2003 3:18 am
Location: Between B and E

Postby Kireihana » Sat Mar 26, 2005 9:26 pm

:eh: You are a braver person than I.
User avatar
Kireihana
 
Posts: 761
Joined: Sat Feb 14, 2004 7:44 pm
Location: Tennessee

Postby LorentzForce » Sat Mar 26, 2005 10:10 pm

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.
Image
User avatar
LorentzForce
 
Posts: 1263
Joined: Sun Jun 01, 2003 3:18 am
Location: Between B and E

Postby twinklebrite271 » Sun Mar 27, 2005 2:09 pm

Yay! It works! Thank you for your help!
Prayer Guardians Thread
CAA Prayer Gaurdians Prayer List
"If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrarily wise, what it would be it wouldn't, and what it wouldn't be, it would." Alice in Wonderland

98% of the teenage population does or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this in your signature.
User avatar
twinklebrite271
 
Posts: 25
Joined: Sun Feb 06, 2005 4:07 pm
Location: Middle Earth


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 127 guests