Jump to content

Custom Function Help


underknown

Recommended Posts

I'm gonna be perfectly honest, I have no idea what's wrong with this code, I'm not even entirely sure what it all means, I just need to make it work. -.-

 

I get this error:  Parse error: syntax error, unexpected '}' in Z:\www\cms\includes\functions.php on line 25

 

From this code:

<html>
<body>
<?php

include('includes/dbvars.php');

function displayVideos($dbc){

mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME');

//Query
$query = "SELECT * FROM videos";

//Execute
$result = mysqli_query($dbc, $query) or die ("Error querying database.");

While ($row = mysqli_fetch_assoc($result)) {
	echo '<h2>' . $row['Title'] . '</h2>';
	echo '<b>Director</b>:' . $row['Director'] . '<br />';
	echo '<b>Description</b>:<br />' . $row['Description'];
	echo '<hr>';
}

mysqli_close($dbc)
}

?>
</body>
</html>

 

 

Any help very much appreciated

Link to comment
https://forums.phpfreaks.com/topic/218646-custom-function-help/
Share on other sites

Yeah, it must've gotten removed when I undid something; new error message:

 

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'DB_HOST' (11001) in Z:\www\cms\includes\functions.php on line 9

 

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in Z:\www\cms\includes\functions.php on line 15

Error querying database.

I did that already, the errors are the same.

 

functions.php:

<html>
<body>
<?php

require_once('includes/dbvars.php');

function displayVideos($dbc){

$dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME');

//Query
$query = "SELECT * FROM videos";

//Execute
$result = mysqli_query($dbc, $query) or die ("Error querying database.");

While ($row = mysqli_fetch_assoc($result)) {
	echo '<h2>' . $row['Title'] . '</h2>';
	echo '<b>Director</b>:' . $row['Director'] . '<br />';
	echo '<b>Description</b>:<br />' . $row['Description'];
	echo '<hr>';
}

mysqli_close($dbc);
}

?>
</body>
</html>

 

dbvars.php:

<html>
<body>
<?php

require_once('includes/dbvars.php');

function displayVideos($dbc){

$dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME');

//Query
$query = "SELECT * FROM videos";

//Execute
$result = mysqli_query($dbc, $query) or die ("Error querying database.");

While ($row = mysqli_fetch_assoc($result)) {
	echo '<h2>' . $row['Title'] . '</h2>';
	echo '<b>Director</b>:' . $row['Director'] . '<br />';
	echo '<b>Description</b>:<br />' . $row['Description'];
	echo '<hr>';
}

mysqli_close($dbc);
}

?>
</body>
</html>

 

Still not sure of what the issue is.  Same error message.

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.