Jump to content

Custom Function Help


underknown
 Share

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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.