PHP - Different value shown when accessing id attribute - php

I am having an issue accessing an attribute from my Laravel app.
A simple query to fetch user is this:
$login = Users::select('user_id' ,'email', 'password')->where('email', Input::get('email'))->first();
I've did dd($login) and it shows the attributes:
But accessing it's user_id shows different (dd($login->user_id)):
accessing email (dd($login->email)) is ok though.
table struct:

Well..looks like a limit to my php.. I'm using 32-bit php where the max integer value is 2147483647..or switch to string.

Related

Creating fusioncharts from database with variable where-condition

I'm creating FusionCharts with data from my database. It works if I set a static where-condition with a variable set in the code ($kommunenr = '3001';). But I would like the user of the website to choose which data the chart is based on, by inserting a number in a form field, i.e. 3018. So the value of the variable should come from the user's choice. But when I test the variable seems empty.
My code is based on these tutorials:
https://www.fusioncharts.com/dev/using-with-server-side-languages/tutorials/php-mysql-charts
https://www.youtube.com/watch?v=nqavhILvBVU
https://a1websitepro.com/jquery-ajax-form-submit-with-php-processing/2/
I have the following files:
valginfo.php (the main page)
skjema.js (get the data (the number) from the form on the main page)
chart_sample.php (lists the data from the database)
app.js (creates the chart)
I have tried to find the error by both posting the content from chart_sample.php in a div on the mainpage, and in an iframe. And of course googling.
My query in my chart-data.php (choosing the data to use in making the chart):
$query = "SELECT * FROM valg19_kommune WHERE kommunenr = $kommunenr AND kandidatnr = 1 ORDER BY kommunenr, sortering, kandidatnr LIMIT 500";
It works if the variable is static, set like this:
$kommunenr = '3001';
But when I set the variable like this, it looks empty:
$nr=$_POST['nr1'];
$kommunenr=$nr;
I expect the posted number to be stored as the value of the variable and beeing part of the query, but it is not. When I echo the query and the result from chart_sample.php into a div on the main page, I looks perfect:
SELECT * FROM valg19_kommune WHERE kommunenr = 3018 AND kandidatnr = 1 ORDER BY kommunenr, sortering, kandidatnr LIMIT 500
[{"label":"Fremskrittspartiet","value":"42","color":"#000099","tooltext":"Elisabeth Stene"},{"label":"H\u00f8yre","value":"64","color":"#3366ff","tooltext":"Benedicte Dyvik"},{"label":"Kristelig Folkeparti","value":"56","color":"#ffff00","tooltext":"Brynjar H\u00f8idebraaten"},{"label":"Senterpartiet","value":"45","color":"#00cc00","tooltext":"Reidar Kaabbel"},{"label":"Arbeiderpartiet","value":"44","color":"#ff3300","tooltext":"Kai Guttulsr\u00f8d"},{"label":"SV - Sosialistisk Venstreparti","value":"39","color":"#ff4d4d","tooltext":"Tore Andersen"},{"label":"R\u00f8dt","value":"37","color":"#cc0000","tooltext":"Martin Werner Olsen"}]
But in my iFrame this is displayed:
SELECT * FROM valg19_kommune WHERE kommunenr = AND kandidatnr = 1 ORDER BY kommunenr, sortering, kandidatnr LIMIT 500[]
The iframe content is not updated when I submit the number.
How can I make sure the chart is made based on the number entered by the user?
Before I enter a number in the form field
After I entered the number
If I set the variable as this $kommunenr = '3001'; and remove the echo og the query.
Now I feel really stupid! I should use sessions and globals!
Start each page with session_start(); and first set and then use the global variables:
$_SESSION["kommunenr"] = $kommunenr;
$kommunenr = $_SESSION["kommunenr"];

Accessing releated field

In FileMaker I have (a.o.) two related tables, where Betreuer_id of table "studentpaper" refers to id of table "Betreuer".
With help of FileMaker's PHP API, I want to access a record in "studentpaper" including the releated fields. Howerver, the later poses a problem. Consider the following PHP code:
$findCommand =& $fm->newFindAllCommand('studentpaper');
$result = $findCommand->execute();
$records = $result->getRecords();
$record = $records[0];
echo $record->getField('Titel'); // okay
echo $record->getField('Betreuer_id'); // okay
echo $record->getField('Betreuer::Name');
// ERROR: get empty string, even related record has a non-empty field
I have expected for "Betreuer::Name" the correct related result, as usually in FileMaker (and as I get in studentpaper's layout). However, I get only an empty string.
What am I doing wrong? Does the relation in FileMaker's PHP-API differs from the "usual" FileMaker approach?
In case anybody is interested, I found the solution on my own.
The problem was that the field wasn't defined (in the layout) as normal text input, but as selection field resticted by a value list.
Thus, one needs to access the value not via the usual getField function but by one of the functions related to value lists. In my case, getValueListTwoFields did the job.

Setting cookie in codeigniter with one name and several values

I want to set a cookie in Codeigniter whenever the user clicks on "add to my favorites". But I'm confused. Because I have to add several items with one name at the same time. You know this is not possible and the CI overrides the previous values. Look at this:
$this->input->set_cookie(array("name"=>'fav', 'value'=>2500, 'expire'=>100000));
$this->input->set_cookie(array("name"=>'fav', 'value'=>3500, 'expire'=>100000));
$this->input->set_cookie(array("name"=>'fav', 'value'=>4500, 'expire'=>100000));
And when I try to get fav value using this function:
printer($this->input->cookie("fav"));
I get this result:
4500
How should I set a cookie for user when they ad an item to their favorite list so that in the moment of retrieving them I know what to retrieve. I cannot use database because this implementation is for the users who are not registered members.
You can use $this->session->set_userdata for storing values.
$fav = $this->session->userdata("my_favs");// get existing list
$fav[] = $new_fav; // append new items to list
$this->session->set_userdata(array("my_favs"=>$fav)); // update session with existing one.
To print all items
$fav = $this->session->userdata("my_favs")
foreach($fav as $fitems)
echo $fitems."<br/>";
I think you should use print_r() instead of printer().
more than that, you should use:
$this->input->get_cookie("fav");
Have a look here for more information: Cookie helper

How can I define a variable in the PHP header ('Location:)

I'm trying to redirect to another page when a record is added to the database.
I want to make sure that this instruction creates an address which contains the id number.
header('Location:inventory_issue_view.php?filterer_client_name=<%%URLVALUE(suiting_reference_no)%%>');
However the address I get from this is
inventory_issue_view.php?filterer_client_name=<%%URLVALUE(suiting_reference_no)%%>
I know the value of
<%%URLVALUE(suiting_reference_no)%%>
is correct since if I edit the instruction to this:
header('Location:inventory_issue_view.php?filterer_client_name=7499');
I get the correct address.
Using this code:
$client=sqlValue("SELECT suiting_reference_no FROM client_suiting WHERE client_name = '{$data['client_name']}'");
I get a null value for $client
Using this code:
$client=sprintf("SELECT suiting_reference_no FROM client_suiting WHERE client_name = '{$data['client_name']}'");
$client=SELECT%20suiting_reference_no%20FROM%20client_suiting%20WHERE%20client_name%20=%20%277489%27
This part of a hook after insert in an APPGini generated script.
An associative array where the keys are field names and the values are the field data values that were inserted into the new record.
* For this table, the array items are:
* $data['issue_date'], $data['client_name'], $data['suiting_ref'], $data['inventory_item'], $data['inventory_qty'], $data['inventory_item_size'], $data['inventory_size_category'], $data['inventory_cost'], $data['inventory_value']
Now that I look at it again an easy solution would be if $client= $data['suiting_ref'] or however one should compose it.
*
How do you get the id of the client? From a query or a form? Hovewer, try:
header("Location:inventory_issue_view.php?filterer_client_name=$clientId");
where $clientId is a variable containing the number.
try this
header("Location:inventory_issue_view.php?filterer_client_name=".$clientId.");
or
header("Location:inventory_issue_view.php?filterer_client_name=$clientId");

PHP PDO get all row names as objects containing value

I have a mySQL database table setup called site.
Rather than qet the column headings to produce a PHP object of values I want to produce data from the rows.
TABLE: site
:::field:::::value:::::
url www.example.com
name example site
etc Example Etcetera
So I want to be able to get this information from the server by calling the column name I want and the row I am after. I want to do this for all fields in site as I don't want to do multiple calls for the various different rows in site; I'd rather store all the information from the beginning in the object:
eg. <? echo $site['url']; ?>
I created this put it appears to be causing an error:.
$sql = "SELECT * FROM `site`";
$site[];
foreach($sodh->query($sql) as $sitefield){
$site[$sitefield['field']] = $sitefield['value'];
}
Obviously I've missed something. ¿Any idea as to what?
$site[];
should be
$site = array();

Categories