Jump to content

parse error i cannot seem to fix


billy61

Recommended Posts

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:
[code]
<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/>";
}
?>[/code]
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:
[code]$query2  = "SELECT * FROM comments WHERE article_id='" . $id . "'";[/code]
any suggestions or solutions?
Link to comment
https://forums.phpfreaks.com/topic/4221-parse-error-i-cannot-seem-to-fix/
Share on other sites

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

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

[code]
$query2 = "SELECT * FROM comments WHERE article_id=' '.$id.' '";
[/code]

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

[code]
$query2 = "SELECT * FROM comments WHERE article_id=$id";
[/code]
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:
[code]<?php
$insert = "INSERT INTO comments(article_id, name, date, comment, ip) VALUES ('$id', '$name', '$date', '$message', '$ip');
?>[/code]
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:
[code]<?php $date   = date('g') . ":" . date('i a M jS'); ?>[/code]
can be written as
[code]<?php $date   = date('g:i a M jS'); ?>[/code]

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:[list][*] 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.[/list]
Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.