Pulling two single variables from a Session Array - php

I have a session that is created and stored. On another page, I want to pull two variables from this session. One of the variables I want to echo as a welcome and the other I want to use in a query to update a mysql table. I just can't quite seem to figure out the correct wording as I have really not worked with sessions and someone else created the initial code. The session name is what is really giving me the trouble.
Here is the code for naming the session:
$directory = "http://$serverName/".$journalName['db'];
mysql_connect('server','user','pass');
mysql_select_db($journalName['db']);
ini_set('session.use_trans_sid', false);
ini_set('session.use_only_cookies', true);
session_name($journalName['db']);
session_set_cookie_params(6*60*60); // 6 hrs until login cookie expires
session_start();
It has the possibility of three different session names. If I do a print of the array (print_r($_SESSION);) here is what shows up:
Array ( [loggedin] => 1 [person] => 1 [account_id] => 1 [order_id] => [type] => individual [unlimited] => yes [status] => active [agreeterms] => no [bounced] => no [subscription_begin] => 0000-00-00 [subscription_end] => 0000-00-00 [contact_name] => Doe, Jane [email] => jane.doe#gmail.com [email_cc] => [institution] => IRA [net_addresses] => [department] => CELT [phone] => 123-456-9383 [address] => 303 S. Patterson Ave [city] => Butte [state] => ID [zip] => 12345 [country] => United States [tech_contact] => [tc_phone] => [tc_email] => [last_login] => 2014-12-15 13:20:24 [last_access] => 2012-03-28 13:45:23 [administrator] => yes [notes] => [last_reset] => 2011-11-19 13:36:59 [last_notified] => 2007-08-14 [combo] => no )
I want to pull the variable contact_name for display at the top of the page and I want to pull the variable email and use it to run and update query. Here is what I currently have to pull the contact_name:
<?php echo "<h2>Account Owner or Contact Name:" .$_SESSION[["contact_name"]]. ",</h2>"; ?>
It is not working at all. Sessions really have me flumoxed at the moment.

Is it possible that you just made a typo ? It seems $_SESSION[["contact_name"]] should be $_SESSION["contact_name"]. Without the extra pair of [] brackets.
And also add
session_start();
to the page, because if you don't the session will not be available

session_start — Start new or resume existing session.
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

Related

Opencart event data missing identifier

Using opencart 3 and trying to make use of the events but I'm unable to find the identifier.
E.g trying to extend the returns form added an event:
$this->model_setting_event->addEvent('mail_account_return_after', 'catalog/model/account/return/addReturn/after', 'extension/module/return/returnAdd');
Controller:
class ControllerExtensionModuleReturn extends Controller {
public function returnAdd(&$route, &$args, &$output) {
print_r($args);
exit;
$args is missing the main return_id identifier:
Array
(
[0] => Array
(
[firstname] => Foo
[lastname] => Bar
[email] => test#gmail.com
[telephone] => 01234556789
[order_id] => 29
[date_ordered] => 2017-06-29
[product] => Canon EOS 5D
[model] => Product 3
[quantity] => 1
[return_reason_id] => 4
[opened] => 0
[comment] => Test comment
)
)
Tried with $this->db->getLastId() but this returns 0. Tested with other events and appears to be missing the main identifiers.
Where does opencart set what data is passed to the before/after events?
If I'm not mistaken you should be able to access the auto increment return_id in $output, which holds the output of method addReturn(), i.e., $this->db->getLastId();.
As to why calling getLastId() a second time from within your event doesn't work, that's a good question. I would assume there may be some other query happening in between - though by default I don't think there should be. Is it possible there is another trigger running a query before your event gets triggered?
Look in system/engine/loader.php at for the strings before and after. There are methods that do view, controller, configuration and language.

How to retrieve a value that is entered on localhost to make a condition

I baked something on cake bake and entering values on local host in that application. The name of the value that i want to retrieve for php script is temperature. how can i get that value?
Here is the some information laying behind the application:
[useDbConfig] => default
[useTable] => temperature_readings
[id] => 32
[data] => Array
(
[TemperatureReading] => Array
(
[temperature] => 15
[location_id] => 5
[created] => 1437572170
[id] => 32
that temperature value, which is 15, is the variable that i want to use in php script.
You can access temperature like this:
$temperature = $array['data']['TemperatureReading']['temperature'];
echo $temperature; //Returns 15

php sort multidimensional array on date column

I have an array $dataStoreForTableImport set up in the following way.
$dataStoreForTableImport['title']
$dataStoreForTableImport['content']
$dataStoreForTableImport['date']
$dataStoreForTableImport['link']
$dataStoreForTableImport['username']
$dataStoreForTableImport['website']
It contains data as below
Array
(
[0] => Array
(
[title] => Quote from Tony Blair
[content] => ... from beating it I'm afraid." (Tony Blair, Sky News) He had every opportunity to put religion in its ...
[articledate] => 28/09/2013
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12890951
[Username] => Michael Dray
[website] => The Motley Fool
)
[1] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... I am irritated that he got such an easy ride; Why? Because he is not to your political liking? He was a witness; he was not on trial and he spoke under oath. What did you expect Jay to ask him? I had dealings with a QC a few years ago. He was as ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564154
[Username] => Michael Dray
[website] => The Motley Fool
)
[2] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... If your doubts about Jay's competence/bias were shared I'm sure it would have been debated ad nauseam on Radio 4. Eh - are you serious? I'm a Radio 4 fan - but thats despite its hatred of all things right of centre, not becuase of. ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564167
[Username] => Michael Dray
[website] => The Motley Fool
)
[3] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... Maybe Tony should have brought Cherie with him - remember Rupert Murdoch and the reaction of Wendi Deng to the custard pie incident. IMHO Cherie is every bit as intimidating:-) Wendi Deng did not eject the pie flinger, she intervened when he acted. Use of an angled bat to deflect criticism from ...
[articledate] => 30/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12565346
[Username] => Michael Dray
[website] => The Motley Fool
)
[4] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... What did surprise me was the fact that he had his own personal bodyguards in the hearing with him. Although, given the level of security that allowed that protester to break into the hearing, maybe he had a point! Eh? He is clearly at risk of terror ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564500
[Username] => Michael Dray
[website] => The Motley Fool
)
I want to be able to remove rows from this array that if the articleDate is before a given date.
I have tried everything but it does not seem to work. I am not even able to get it to sort correctly by date?
The date comes in the format - February 10, 2007
I have used
$sortDate = date('d/m/Y', strtotime($sortDate));
to format it to the format shown in the array above.
Can anyone please help?
Thanks
Mike
Do the filtering and sorting of rows in the database backend. This will improve the performance of you app. Use a WHERE clause for filtering by date and an ORDER BY clause for ordering by date in you SQL query.

Redbeanphp - Getting data from foreign key index

Sorry for the vague title, if anyone would like to edit it to reflect more about what I am posting, please do so. Here is the situation. I have 3 tables:
support:
id | contact_id | title | problem | etc
supportlogin:
id | contact_id | login | pass | etc
contact:
id | first_name | last_name | email | etc
I am loading the support bean just fine, and am accessing the contact info:
$support=R::load('support',1);
echo $support->contact->first_name;
I want to echo the supportlogin information similarly:
echo $support->contact->ownSupportlogin->login;
Is this possible, and am I doing it the right way? I have tried the following ways with no success:
echo $support->contact->supportlogin->login;
echo $support->contact->ownSupportlogin->login;
echo $support->contact->ownSupportlogin[0]->login;
EDIT: MORE INFO
I did print_r($support->contact) and was given the data:
RedBean_OODBBean Object
(
[null:RedBean_OODBBean:private] =>
[properties:RedBean_OODBBean:private] => Array
(
[id] => 109
[phone] => 1234580970
[first_name] => Tim
[last_name] => Withers
)
[__info:RedBean_OODBBean:private] => Array
(
[type] => contact
[sys.id] => id
[tainted] =>
)
[beanHelper:RedBean_OODBBean:private] => RedBean_BeanHelperFacade Object
(
)
[fetchType:RedBean_OODBBean:private] =>
)
And then I did print_r($support->contact->ownSupportlogin) and this showed up:
Array
(
[13] => RedBean_OODBBean Object
(
[null:RedBean_OODBBean:private] =>
[properties:RedBean_OODBBean:private] => Array
(
[id] => 13
[link] => fecd4ef67e8c789efa1792f9ee0efff4
[login] =>
[password] =>
[receiveemails] => 1
[contact_id] => 109
[role] => 1
)
[__info:RedBean_OODBBean:private] => Array
(
[type] => supportlogin
[sys.id] => id
[tainted] =>
)
[beanHelper:RedBean_OODBBean:private] => RedBean_BeanHelperFacade Object
(
)
[fetchType:RedBean_OODBBean:private] =>
)
)
I can access it using: echo $support->contact->ownSupportlogin[13]->login;, but doing it dynamically seems to be a problem....
Figured it out, and will leave it up in case anyone else has a similar problem:
This will only work if you have a 1:1 relationship. Redbean populates the ownSupportlogin as an array of all supportlogin rows related to the contact. If one table can have many child tables, then you will need to loop through that array and pull out the data you want. If it is a 1:1 relationship, then you can use PHP's reset() to access the data of the first element in the array:
echo reset($support->contact->ownSupporlogin)->login;

saving cakephp date fields

I have a form that includes an hour and minute drop down using this: 'dateFormat'=>'NONE', 'timeFormat'=>'24' But now when i save the form $this->data ends up looking like the array below and because eventStartDate & eventStartDate are arrays it makes an SQL error saying eventStartDate can not be null etc.
Array
(
[Work] => Array
(
[eventStartDate] => Array
(
[hour] => 12
[min] => 00
)
[eventEndDate] => Array
(
[hour] => 12
[min] => 45
)
[description] => 234
[projectID] => 7105
[taskID] => 1
[userid] => 8
)
)
Shouldnt cakephp make these arrays into strings so they can be put into the database automatically?
What values for day, month etc will be used?
This might help, as it worked for me:
Your view code should look something like this
echo $form->dateTime('your_column_name', 'NONE', '24');

Categories