I am trying this in Joomla
, but i getting error
Catchable fatal error: Object of class JUser could not be converted to string in C:\xampp\htdocs\Joomla\components\com_jumi\jumi.php(25) : eval()'d code on line 3
Try below instead of your code.
<?php
$user =& JFactory::getUser();
print_r($user);
?>
This will work because the first line will return the object and you are trying to print the object using echo.
If you want to get user name the try below code.
<?php
global $mainframe;
$User_name = $mainframe->getuser()->get('name');
?>
above code will return name of the logged in user.
Related
I'm trying to create a dummy login page as a practice. I keep getting this error:
Call to undefined method mysqli_result::fetch_both()
Code:
<?php
if (isset($_POST['LOGIN'])){
$EMAIL = $_POST['loginusernameinput'];
$PASS = $_POST['loginpasswordinput'];
$result = $conn->query("SELECT * FROM userinformationtbl WHERE Email ='$EMAIL' AND password ='$PASS'");
$row = $result -> fetch_both(MYSQLI_BOTH);
session_start();
$_SESSION["userID"] = $row["userID"];
header ('location: account.php');
}
?>
Unless you defined it in your code, fetch_both is not a PHP function.
That's why you get:
Call to undefined method mysqli_result::fetch_both()
PDO::FETCH_BOTH is a constant in the PDO class, which means it can only be used with a PDO connection and PDO functions.
MYSQLI_BOTHis a MySQLi constant.
Fix your code:
$row = $result->fetch_array(MYSQLI_BOTH);
Documentation: mysqli_result::fetch_array
I am unable to access zend session in included file via layout.
what i have done so far -
//bootstrap
public function _initSession()
{
Zend_Session::start();
$test = new Zend_Session_Namespace('test');
}
//controller
public function init(){
$test = new Zend_Session_Namespace('test');
$test->abc = 'defghi';
}
//layout include file
<?php include_once( APPLICATION_PATH . '/data/ga_test.php');?>
//ga_test.php
$test = new Zend_Session_Namespace('test');
echo 'this is ' . $test->abc;
I am not able to access the variable in ga_test file. I am getting an empty variable. But if I include ga_test end of each view file then it works. Obviously I don't want to go to every view file and include ga_test.php. Can I do this via layout.
I am sure, I am doing something wrong here. Any help would be really appreciated.
Thanks
I'm having some trouble with a block of code I'm trying to implement.
My thought process was to have different users with different attributes in the "userType" (which is an INT type) column in my database and to have a switch case to take the result of the query and select which page to redirect to. The links for re-direction haven't been inserted yet as the login switch case isn't working.
Here is the code for my "loginsuccess.php"
<?php
session_start(); // Right at the top of your script
?>
<?php
ob_start();
$host="localhost"; // Host name
$username="google_test"; // Mysql username
$password="password"; // Mysql password
$db_name="google_test"; // Database name
$tbl_name="user"; // Table name
$mysqli = new mysqli($host, $username, $password, $db_name);
if($_SESSION['$myusername']==true)
{
$sessionUsername = $_SESSION['$myusername'];
$userType = "SELECT userType FROM '$tbl_name' WHERE username='$sessionUsername'";
$result = mysqli_query($mysqli, $userType);
switch ($result){
case "1":
//userType 1 is admin
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome Admin.";
break;
case "2":
//userType 2 is business
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome to your business page.";
break;
case "3":
//userType 3 is general user
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome to the Fun Finder App!!.";
break;
default:
echo $_SESSION['$myusername'];
echo ", it appears that your user type has not been defined yet.";
echo " Please contact support to resolve this issue.";
}
}
elseif($_SESSION['$myusername']==false)
{
echo "oops......";
//echo '<span>Login/Register</span></li>';
}
ob_end_flush();
?>
My login script is working and passes the username and password through the database successfully via another php page. The result I'm getting from this php file is that the switch case goes directly to the default case regardless of which login I use. I'm assuming it is something to do with my query not returning the proper result as I tried to echo the $result variable and got nothing. Php is not my strongest language so any help would be appreciated. Thanks in advance!
Mysqli_query returns a result object and not the actual value. You can read the value from that object however:
http://php.net/manual/en/mysqli.query.php
As an additional hint: it might make sense to store these user privileges along with the user login name in the session once the user succesfully authenticates. (There might be more places where this info is needed - that way you don't need to do queries all the time)
The only drawback is that this will not respond to permission chamgesnfor that user (when a user becomes admin he will need to login again)
In my opinion you must use mysql_fetch_array() to store the result from the database before using it in a switch case.
example:
$row=mysql_fetch_array($result);
$privilege=$row['usertype']; //user type is from the column in your table
I used Like this But This is not Working
$msg=array('id' =>'Account Sucessfully Deleted');
$this->_redirect('customer/account/dresshoheaccount',$msg);
i want $msg Print in My Page,
you can easily do this as follows :
Mage::getSingleton('catalog/session')->addSuccess($this->__('Account Sucessfully Deleted'));
Please note that insert this line before you laid your layout.
you can call this is template as :
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
If not helping, try to add messages not to catalog/session, but to core/session.
Problem:
form processing script throws error when returning back to the calling script which is the user entry form.
error message
Notice: A session had already been started - ignoring session_start() in /inc/utilities.inc.php on line 3 Fatal error: Cannot redeclare class Connection in /inc/dbconn.php on line 5
The code is a bit too large to copy past all of it so im just going to focus on the problem area.
newproject.php calls -> savenewproject.php. if savenewproject.php finds error it returns back to newproject.php to display error message.
//newproject.php - parts of the code that i believe is the problem area.
<?php
include('../inc/utilities.inc.php');
include('header.php');
if (!empty($errorString))
{ echo '<div class="error">' . $errorString . '</div>'; }
if (!empty($successString))
{ $emailaddress = '';
$budget = '';
$projecttitle ='';
$projectdescription = '';
echo '<div id="divfadeout" class="success">' . $successString . '</div>';
}
?>
<form name ='newProject' action="../inc/savenewproject.php" enctype="multipart/form-data" method="POST">
the rest are form fields
</form>
// include('../inc/utilities.inc.php'); - appears in both script
<?php
session_start();
$user = (isset($_SESSION['user'])) ? $_SESSION['user']: null;
include("../inc/dbconn.php");
?>
// savenewproject.php - copy/pasting what i believed to be the problem area.
if(count($fieldErrors) > 0)
{ $errorString = '<p>There was an error processing the form.</p>';
$errorString . 'ul>';
foreach($fieldErrors as $errorVal)
{ $errorString .= "<li>$errorVal</li>"; }
$errorString .= '</ul>';
include ('../layout/newproject.php');
}
else
{
looks like i answered my own question..
instead of include i used request once and it seems to have fixed the probelm..