I'm having trouble sending data via sessions because I'm getting errors of undefined variable while defining the variable in controller/checkout/shipping_address.php under validate() function. (checkout/shipping_address/validate).
$this->session->data['ship_date'] = $this->request->post['ship_date']; //<- line 102
In controller/checkout/shipping_method
$ship_date = $this->session->data['ship_date'];
if(empty($ship_date)) echo "var empty";
$ship_date = explode("-", $ship_date);
$ship_date = $ship_date[0] . "/" . $ship_date[1] . "/" . $ship_date[2];
and then I do
$quote = $this->{'model_shipping_' . $result['code']}->getQuote($shipping_address, $ship_date);
Also yes, in model/shipping/fedex.php I allow usage of $ship_date parameter. Yet after that I get.
Invalid JSON: Notice: Undefined index: ship_date in
/var/www/catalog/controller/checkout/shipping_address.php on
line 102[] parsererror Notice: Undefined index:
ship_date in
/var/www/catalog/controller/checkout/shipping_address.php on
line 102[]
You should debug the arrays $this->session->data and $this->request->post.
The reason you see those errors is that there is no index ship_date in $this->session->data and in $this->request->post. So you get a Notice: Undefined index:.
Because of the notices that are printed your afterwards outputted json becomes invalid.
Actually, OpenCart only talks through JSON. So adding this will help.
$JSONarray = array("date" => $this->request->post['ship_date']);
$this->session->data['ship_date'] = json_encode($JSONarray);
When you want to use it,
$JSONarray = $this->session->data['ship_date'];
$arr = json_decode($JSONarray, TRUE);
$Value = $arr['ship_date'];
We have to make the data JSON and then send it
Related
I have been searching the internet for hours now, and i can't figure it out.
<?php
$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"}{"name": "Letter","value": "letter"}]}{"title": "Title","name": "title","type": "text"}{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"}{"title": "Submit","type": "submit"}]}]}';
$result = json_decode($json, true);
var_dump($result);
echo $result['pages'][0]['name'];
echo $pages[0]['name'];
?>
Im just simply trying to parse some json but the website says this:
NULL
Notice: Undefined variable: pages in C:\Users\hazzj\Desktop\Stuff\Apache-Server\htdocs\WMS\Author\submit\test.php on line 7
You'd missed out commas between strings {}. Use this modified $json variable:
$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"},{"name": "Letter","value": "letter"}]},{"title": "Title","name": "title","type": "text"},{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"},{"title": "Submit","type": "submit"}]}]}';
$result = json_decode($json, true);
echo $result['pages'][0]['name']; // Output: Page1
echo $pages[0]['name']; // Not sure what this $pages variable is
I have this JSON (is from Steam Market):
{"success":true,"lowest_price":"$5.79","volume":"2,932","median_price":"$5.79"}
And I have this code:
$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='.$name;
$market = json_decode(file_get_contents($urlm), true);
echo $market['lowest_price'];
But when I try it, they give me an error:
Notice: Undefined index: lowest_price
What is wrong? Because I have an other JSON with the same method and works perfect.
You should urlencode your varaiable:
$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='. urlencode($name);
Hi I have this json code
{"points":[ {"10":"10"}, {"1":"1"} ]}
and this is my php code
$pointsfirst = $row['points'];
$points = json_decode($pointsfirst,true);
$getit = $points['points'][1]['10'];
echo $getit;
$row['points'] is from my database where I have stored the json
and I keep getting this error
Notice: Undefined offset: 10 in
/Applications/MAMP/htdocs/projectg/getpointsapi.php on line 46
what am I doing wrong ??
Right way is:
$getit = $points['points'][0][10];
echo $getit;
Try
$getit = $points['points']['1']['10'];
with the quotas! instead...
Arrays in PHP start with offset 0, not 1. This means you should probably use $getit = $points['points'][0]['10']; instead.
trying to get every post and comment from a facebook page, I made this function that should go through the pagination:
$req = $facebook->api("/" . $pagename . "/?fields=posts.fields(message,link,created_time,shares,likes,comments)");
function parcours_arbre($ab)
{
GLOBAL $facebook;
GLOBAL $pagename;
$next = create_request($ab['posts']['paging']['next']);
$next_req = $facebook->api($pagename.$next);
$ab_next = $next_req['data'];
$prev = create_request($ab['posts']['paging']['previous']);
$prev_req = $facebook->api($prev);
$ab_prev = $prev_req['data'];
if (empty($ab)) {
display_results($ab['posts']['data']);
} else {
parcours_arbre($ab_next);
parcours_arbre($ab_prev);
}
}
I unfortunately get the following error:
Notice: Undefined index: posts in /form.php on line 36
Notice: Undefined offset: 3 in /utils.php on line 20
Notice: Undefined offset: 4 in /utils.php on line 20
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /sdk/src/base_facebook.php on line 1271
Any idea how i could avoid it or what is going on? Would this go away if i use the "until" statement in my api request?
Thanks a lot,
To explain each error
the variable $ab which is an argument to the function, does not have a "posts" index. You should try to var_dump this variable so you can see what it actually looks like.
same as above
same as above
the api function takes 3. The path which should just be #pagename. The method ("GET" or "POST") most likely POST because GET is causing an error. The parameters, which should be array("fields" => "posts.fields(message,link,created_time,shares,likes,comments)")
I noticed that for next you have the code
$next_req = $facebook->api($pagename.$next);
but for previous you have
$prev_req = $facebook->api($prev);
Might want to look into this.
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
Notice: Undefined index: subject in /var/www/mailer.php on line 12 Notice: Undefined index: message in /var/www/mailer.php on line 13 Notice: Undefined index: from in /var/www/mailer.php on line 14 Notice: Undefined index: verif_box in /var/www/mailer.php on line 15 Notice: Undefined index: tntcon in /var/www/mailer.php on line 23 no variables received, this page cannot be accessed directly
BELOW IS THE CODE
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
// remember to replace you#email.com with your own email address lower in this code.
// load the variables form address bar
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$verif_box = $_POST["verif_box"];
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("abhijit.infogence#gmail.com", 'TheWebHelp.com Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
} else {
echo "no variables received, this page cannot be accessed directly";
exit;
}
?>
You're trying to access parts of a variable which don't exist. You may want to check before using them, if they exist.
The error is simply because the message $_POST array does not have a key called 'message'. It probably comes from the fact that the form has not been submitted. The error is only a notice and won't stop the program from working.
You should check what $_POST contains before you address some particular fields, take a look at the isset function. Or simply turn off display_errors ;)
It seems that you call this PHP file without submitting a form via the POST method. Make sure that your mailing form has the proper method set:
<form method="POST" action="yourfile.php">
etc.
</form>
You should also sanitize the user input before calling mail() (i. e. remove newlines and tags), otherwise you are calling for trouble.
Your $_POST and $_COOKIE arrays do not contain those indexes.
Do:
print_r($_POST);
print_r($_COOKIE);
to see what is contained in those arrays
foreach(array('subject', 'message', 'from', 'verif_box') as $val)
{
if (isset($_POST[$val]))
{
$$val = trim($_POST[$val]);
continue;
}
// some sort of error checking, like telling the end user that
// not all fields were correctly given
}
Check user-submitted data
$subject = (isset($_POST["subject"]) ? $_POST["subject"] : '');
$message = (isset($_POST["message"]) ? $_POST["message"] : '');
$from = (isset($_POST["from"]) ? $_POST["from"] : '');
$verif_box = (isset($_POST["verif_box"]) ? $_POST["verif_box"] : '');
You can even make your own function to do that
function checkPost($fieldname)
{
return (isset($_POST[$fieldname]) ? $_POST[$fieldname] : '');
}
And then do
$subject = checkPost("subject");
I recommend as well that you check required POST fields
if (!isset($_POST["xxx"]) || trim($_POST["xxx"]) == '')
{
// throw exception, display error...
}
etc.
FYI, instead of using stripslashes() to avoid "magic_quotes", you can use a simple function such as this one http://snippets.dzone.com/posts/show/5256 which will do the job for all fields.
//checking if array elements are set and changing variables values if so
$subject = isset($_POST["subject"])?$_POST["subject"]:null;
$message = isset($_POST["message"])?$_POST["message"]:null;
$from = isset($_POST["from"])?$_POST["from"]:null;
$verif_box = isset($_POST["verif_box"])?$_POST["verif_box"]:null;
// check to see if verificaton code was correct and if cookie value on 'tntcon' is set
if(isset($_COOKIE['tntcon']) && md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
Changes are on lines 12-15 and in 23.