Jump to content

[SOLVED] Stuck at an "unexpected $end"


jamcoupe

Recommended Posts

I am just trying to make a simple news script. I am trying to display all the news posts and their comments underneath them. Any ideas why I am getting:

Parse error: syntax error, unexpected $end in /Applications/MAMP/htdocs/jstar/test.php on line 69

 

Heres my code:

<?php
require("constants.php");

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
query_check($connection);


$db_select = mysql_select_db(DB_NAME, $connection);
query_check($db_select);
?>
<?php
function query_check($check) {
if(!$check) {
	die ("OOOPS: " . mysql_error());
}
}

function get_news() {
global $connection;
$query = ("SELECT * FROM news ORDER BY id ASC");
query_check($query);
$news = mysql_query($query, $connection);
return $news;
}

function get_comments($id) {
global $connection;
$query = ("SELECT * FROM comments WHERE newsid = {$id} ORDER BY id ASC");
query_check($query);
$comments = mysql_query($query, $connection);
return $comments;
}

//This will enable 
function get_news_id($news_id) {
global $connection;
$query = ("SELECT * FROM news WHERE id={$news_id} LIMIT 1");
$query = mysql_query($query, $connection);
query_check($query);
if($id = mysql_fetch_array($query)) {
	return $id;
} else {
	return NULL;
}
}
?>
<?php

$get_news = get_news();

while ($news = mysql_fetch_array($get_news)) {
	echo "{$news['title']}<br />";

	$get_comments = get_comments($news['id']);

	while ($comments = mysql_fetch_array($get_comments)) {
		echo "{$comments['comment]}<br />";
	}
}

?>
<?php
if(isset($connection)) {
mysql_close($connection);	
}
?>

Link to comment
https://forums.phpfreaks.com/topic/169712-solved-stuck-at-an-unexpected-end/
Share on other sites

There is no problems with that script. Your code works fine.

 

However I do not see the point in doing

<?php

// some php code here
?>
<?php

// some more php code here

?>

 

If you're not going to put anything between the code blocks then there is no need to go out of php and then immediately back in to php.

 

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.