Jump to content

$lang inside function


jacob21
Go to solution Solved by Barand,

Recommended Posts

I have included language file and function file in my index.php

include 'includes/functions.php';
include 'languages/english.php';

english.php contains

<?php
$lang['success']['a'] = 'Settings have been updated.';
$lang['error']['b'] = 'Database error. Please try again later!';

.................................
?>

functions.php

<?php
function testFunction($id, $settings, $db){
	
	$query = 'UPDATE table_name SET a = a + :a WHERE id = :id';
	$update = $db->prepare($query);
	$update->bindParam(':a', $settings['a'], PDO::PARAM_INT); 
	$update->bindParam(':id', $id, PDO::PARAM_INT);  
	$success = $update->execute();
	
	if($success){
		print $lang['success']['a'];
	}else{
		print $lang['error']['b'];
	}
	
}

.................................................

?>

Now if i print testFunction(); i got Undefined variable: lang in .............  If i include 'languages/english.php'; in testFunction() then everything works. Any other way to make $lang working without including language file in testFunction(). (Sorry for my  bad english)

print testfunction(2, $settings, $db);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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