underknown Posted November 14, 2010 Share Posted November 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/ Share on other sites More sharing options...
ignace Posted November 14, 2010 Share Posted November 14, 2010 You will have to show us the code from: Z:\www\cms\includes\functions.php Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134089 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 That is functions.php; the unexpected '}' seems to be the one that closes the function statement, but I can't see why that would be unexpected, and if I take it out I get an unexpected end from the </html> tag at the bottom... Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134091 Share on other sites More sharing options...
marcus Posted November 14, 2010 Share Posted November 14, 2010 You're missing the semi-colon on your mysqli_close line. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134097 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 New error message now at least: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in Z:\www\cms\includes\functions.php on line 13 Error querying database. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134100 Share on other sites More sharing options...
marcus Posted November 14, 2010 Share Posted November 14, 2010 Make your connection line: $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134102 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 Alright, I changed it, but now it's back to: Parse error: syntax error, unexpected '}' in Z:\www\cms\includes\functions.php on line 25 Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134135 Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 are you still missing that semi-colon? Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134137 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134139 Share on other sites More sharing options...
marcus Posted November 14, 2010 Share Posted November 14, 2010 That's your problem, you have invalid database information. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134153 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 Well here's the dbvars.php code, but I can't see any mistakes with the host. <html> <body> <?php //Defines Vars define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PW', 'root'); define('DB_NAME', 'functions'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134154 Share on other sites More sharing options...
Pikachu2000 Posted November 14, 2010 Share Posted November 14, 2010 Change mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); to $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); And then see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134163 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134164 Share on other sites More sharing options...
underknown Posted November 14, 2010 Author Share Posted November 14, 2010 I tried entering the values from dbvars.php into functions.php directly in the connect statement, which works fine. I'm not sure what's wrong though, given the fact that I'm sure they're exactly the same. Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134179 Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 being declared constants, i don't think those strings should be quoted. but i have been wrong before... $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME); Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134187 Share on other sites More sharing options...
underknown Posted November 15, 2010 Author Share Posted November 15, 2010 Frig...yeah you're right....I dunno how I missed that. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/218646-custom-function-help/#findComment-1134206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.