Jump to content


Photo

parse error i cannot seem to fix


  • Please log in to reply
3 replies to this topic

#1 billy61

billy61
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 05:29 PM

alright, so i'm workin on the comment system for my blog im building.....
things are going smoothly, but i cannot seem to find the culprit of this error:

Parse error: parse error, unexpected T_STRING in c:\appserv\www\bi30\tables2\comment.php on line 49

comment.php:
<body>
<?php
$connect  = mysql_connect(localhost, root)
        or die('Could not connect :<br/>' . mysql_errno() . " : " . mysql_error());



$dbconnect = mysql_select_db(content)
        or die('Could not find db :<br/>' . mysql_errno() . " : " . mysql_error());
$query1  = "SELECT * FROM articles WHERE id='" . $id . "'";
$result1 = mysql_query($query1)
        or die('Could not query :<br/>' . mysql_errno() . " : " . mysql_error());
while($r1 = mysql_fetch_array($result1)) {
    $title   = $r1['title'];
    $author  = $r1['author'];
    $date    = $r1['date'];
    $article = $r1['message'];
    
    echo "<b>" . $date . "</b>" . "<br/><br/>";
    echo "<h1><b>" . $title . "</b></h1>" . "<br/><br/>";
    echo $author . "<br/><br/>";
    echo $article;
}

$date   = date('g') . ":" . date('i a M jS');
$insert = "INSERT INTO comments(article_id, name, date, comment, ip) VALUES ('$id', '$name', '$date', '$message', '$ip');

echo '<br/><br/>';
$query2  = "SELECT * FROM comments WHERE article_id='" . $id . "'";
$result2 = mysql_query($query2)
        or die('Could not query :<br/>' . mysql_errno() . ' :; . mysql_error());
while($r2 = mysql_fetch_array($result2)) {
    $article_id = $r2['article_id'];
    $comment_id = $r2['comment_id'];
    $name       = $r2['name'];
    $date       = $r2['date'];
    $comment    = $r2['comment'];
    $ip         = $r2['ip'];

    echo $date;
    echo $comment . "<br/><br/>";
}
?>
i cut out some css styling at the top to save space, so the line numberings are off from my real document, line 49 is:
$query2  = "SELECT * FROM comments WHERE article_id='" . $id . "'";
any suggestions or solutions?

#2 mem0ri

mem0ri
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 06 March 2006 - 05:38 PM

[!--quoteo(post=352113:date=Mar 6 2006, 09:29 AM:name=billy61)--][div class=\'quotetop\']QUOTE(billy61 @ Mar 6 2006, 09:29 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$query2  = "SELECT * FROM comments WHERE article_id='" . $id . "'";
[/quote]

Looks like you've got too many quotes in your SQL statement...

$query2 = "SELECT * FROM comments WHERE article_id=' '.$id.' '";

Dunno why you're puttin' whitespace in front of and after the $id...I'd just do:

$query2 = "SELECT * FROM comments WHERE article_id=$id";


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 March 2006 - 06:20 PM

When you get an error like this and can't find the error on the line PHP is pointing to, go back one line at a time and look for unmatched quotes (either single or double). In your case, you are missing an ending double quote on this line:
<?php
$insert = "INSERT INTO comments(article_id, name, date, comment, ip) VALUES ('$id', '$name', '$date', '$message', '$ip');
?>
Insert a double quote before the semi-colon.

To the previous poster .. the line you quoted is fine, a little unorthodox, but fine.

To the OP, you have some convoluted code that can be simplified:
You line:
<?php $date   = date('g') . ":" . date('i a M jS'); ?>
can be written as
<?php $date   = date('g:i a M jS'); ?>

You seem to use double quotes and single quotes without rhyme or reason. If you only use double quotes where you need one of these things to happen:
  • The value of a variable needs to be included
  • A special character needs to be inserted or used.
  • A single quote needs to be inserted into a string.
Ken


#4 billy61

billy61
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 08:43 PM

thanks a bunch guys, that cleared things up
it was kenrbnsn's tip that fixed it, but mem0ri had some good advice none the less.

thanks...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users