PROBLEM WITH INSERT $_POST + VARIABLES

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
morena84
Forum Newbie
Posts: 9
Joined: Thu Apr 03, 2008 9:52 am

PROBLEM WITH INSERT $_POST + VARIABLES

Post by morena84 »

Hi there!

I am new to this forum so I would like to say hello to everybody.

What I am working on is http://www.morenafiore.com/blog

I have working code for
- inserting new blog entry
- showing blog entries
- showing comments for every blog entry (comments that I have inserted from my mysql admin website)


I can not insert new comments though. It works like this: you have the blog entries on the main page ---> you click onto "Read comment" button ---> it takes you to the comment page for that post and i can see the comments fine.

There is a form underneath the comment to insert a new comment but i get the error "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\inetpub\webs\morenafiorecom\blog\entries\okcomment.php on line 107" when trying to insert a new post.

Here's the code:

- form from the main page carrying the "entryid" hidden field:
<? echo "<form name='read comment' action='entries/readcomment.php'method='get'>";
echo "<input type='hidden' name='entryid' value='{$row['entryid']}'></input>";
echo "<input type='hidden' name='title' value='{$row['title']}'></input>";
echo "<input type='submit' value='Read comments' STYLE='font-family:sans-serif; font-size:10px; background:#FFe9ca none; bordercolor:#FFe9ca;'></input></form>"; ?>


- This is the code in the readcomment.php page:
<? echo "<h1>\"$title\"</h1><p class='commentstitle'>Comments: $comment_num</p>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ;
echo "<p class='commentstitle'><strong> {$row['author']} </strong>said:<br>" ;
echo "<span style= font-family:arial; font-size:20px;'>\"</span>{$row['comment']}<span style= font-family:Arial; font-size:20px;'>\"</span><div id='line'>&nbsp</div>";
} ?>
<form class="form" name="leavecomment" action="okcomment.php" method="post">
<input type="hidden" name="numero" value=<? $row['entryid'] ?> ></input>
<label>Comment <textarea name="text" cols="60" rows="6" class="form" id="text"></textarea></label>
<p><label>Author<input name="author" type="text" class="form" id="author" size="60" maxlength="100"></textarea></label><p>
<input type="submit" value="Leave a comment" STYLE="font-family:sans-serif; font-size:10px; background:#FFe9ca none; bordercolor:#FFe9ca></input></form></p></p>


- This is the code in the okcomment.php page that should confirm the comment has been inserted:
<? $day = date('d');
$month = date('m');
$year = date('Y');
mysql_select_db (DB_NAME);
if (!$dbc)
{
die('Could not connect: ' . mysql_error());
}

$sql="INSERT INTO comments (entryid, comment, author, day, month, year)
VALUES ('$_POST['numero']','$_POST['text']','$_POST['author']', '.$day.', '.$month.', '.$year.');

if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}
echo "1 comment added";mysql_close($dbc)
?>

any suggestion on what i am doing wrong?(probably everything :)

morena
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: PROBLEM WITH INSERT $_POST + VARIABLES

Post by EverLearning »

Use code=php tags. If you did, you would have spotted the error immediately - an unclosed string.

Code: Select all

 
$sql="INSERT INTO comments (entryid, comment, author, day, month, year)
VALUES ('$_POST['numero']','$_POST['text']','$_POST['author']', '.$day.', '.$month.', '.$year.');
 
if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}
 
 
:arrow:

Code: Select all

 
$sql="INSERT INTO comments (entryid, comment, author, day, month, year)
VALUES ('$_POST['numero']','$_POST['text']','$_POST['author']', '.$day.', '.$month.', '.$year.')";
 
if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}
 
See? Use some IDE with syntax highlighting,, it helps :)
Post Reply