Using PHP to send HTML and PHP code to a website - php

I am getting a list of errors I can't work out. I have the bellow array in tools.php
$movie = array(
'act' => array (
'movieName' => 'Avatar: The Way of Water',
'moviePoster' => 'act.jpg',
'movieClassification' => 'M',
'movieClassificationText' => 'SciFi, Adventure, Fantasy, Action',
'movieReleaseDate' => '15th of December 2022',
'movieLength' => '192 Minutes',
'movieGenre' => 'SciFi, Adventure, Fantasy, Action',
'movieDistributor' => 'Walt Disney Studios',
'movieOverview' => ''',
'movieDirector' => 'James Cameron',
'movieActor1' => 'Sam Worthington',
'movieRole1' => 'Jake Sully',
'movieActor2' => 'Zoe SaldaƱa',
'movieRole2' => 'Neytiri',
'movieActor3' => 'Sigourney Weaver',
'movieRole3' => 'Kiri',
'movieTrailer' => ''));
and then also some code that creates the HTML for the Banners depending on the different movie code.
echo '<div class="slide_image">
<img src='../../media/a3/backdrop/".$movie['act']['moviePoster']."' alt='".$movie['act'] ['movieName']."'> <-- Line 107
</div>
<div class="slide_information">
<h2>Now Showing</h2>
<h3>.$movie['act']['movieName'].</h3> <-- Line 111
<button type="button" class="btn_book_now">Book Now</button>
</div>';
when I run the code above i get the following errors for line 107 and line 111.
Warning: Undefined variable $movie in C:\xampp\htdocs\wp-1\a3_test\tools.php on line 107
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\wp-1\a3_test\tools.php on line 107
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\wp-1\a3_test\tools.php on line 107
I have tried to change the way the code is written using $banner = "Something" and return $banner but that gives me a lot of different issues.

Related

Laravel : One to many relational data update

I have the following code :
foreach ($request->dog_vaccine_required as $key => $vaccine) {
$serviceVaccination = \App\UserServiceVaccination::updateOrCreate([
'user_service_id' => $id,
'vaccine_id' => $vaccine
],[
'specie' => 'Dog',
'user_service_id' => $id,
'vaccine_id' => $vaccine,
'duration_6' => $request->dog_duration_6[$key],
'duration_12' => $request->dog_duration_12[$key],
'duration_36' => $request->dog_duration_36[$key]
]);
}
Now the data coming along from the form is :
It gives me exception :
Undefined offset: 2
The request dog_duration_6, dog_duration_12, dog_duration_36 arrays can be different in terms of element size,
How can i pass null to avoid exception Undefined offset: 2 ?
Simply add a check like to avoid offset exception.:
isset($request->dog_duration_6[$key]) ? $request->dog_duration_6[$key] : null
For all of them.
'duration_6' => $request->dog_duration_6[$key] ?? null,

Undefined offset:1

$aa = Input::get('AccountOpeningDate' . $i);
$dateinfo = explode("-", $aa);
$testDay = Carbon::createFromDate($dateinfo[0], $dateinfo[1],
$dateinfo[2], 'UTC');
$actualDate = $testDay->setTimezone('+6:00');
when I run this code then I get an output.But it cause an error that like the image below.
ErrorException in MemberController.php line 532:
Undefined offset: 1
in MemberController.php line 532
at HandleExceptions->handleError('8', 'Undefined offset: 1', 'C:\xampp\htdocs\timf\app\Http\Controllers\MemberController.php', '532', array('id' => '4001-5088-0565', 'memberdata' => object(Member), 'somityDay' => object(Zone1), 'i' => '2', 'aa' => '', 'dateinfo' => array(''), 'testDay' => object(Carbon), 'actualDate' => object(Carbon), 'producttype' => '2', 'memberaccount' => object(Accountstable), 'valsa' => object(Product), 'AccNameSub' => 'MSSM', 'accnumber' => 'MSSM.4001-5088-0565', 'k' => '13', 'SavingSetup' =>
This code is written in laravel 5.1.
$aa = Input::get('AccountOpeningDate' . $i);
Here $aa has no data in case of any conditions. So the array $dateinfo remaining empty. I have fixed the problem by ensuring $aa data not empty.
now the code is running well.
There may be a comma missing in your first line of code.

Cast double to int inside Smarty

I am trying to display double variable inside an Smarty environment converting it into int.
The File configuring the variables has the following code.
The Variable PRODUCTS_Quantity_x is the viewed Variable which I added. It is giving me a comma separated value with 3 fractional digits. The {$module_data.PRODUCTS_Quantity} is already be able to get displayed in through the html.
I have already tryed things like count() etc. I mostly got an empty variable or smarty errors ...
$t_data_array = array ( 'PRODUCTS_NAME' => htmlspecialchars_wrapper($array['products_name']),
'COUNT' => $array['ID'],
'PRODUCTS_ID' => $array['products_id'],
'PRODUCTS_VPE' => $this->getVPEtext($array, $products_price['plain']),
'PRODUCTS_IMAGE' => $this->productImage($array['products_image'], $image),
'PRODUCTS_IMAGE_W' => $array['products_image_w'],
'PRODUCTS_IMAGE_H' => $array['products_image_h'],
'PRODUCTS_IMAGE_WIDTH' => PRODUCT_IMAGE_THUMBNAIL_WIDTH,
'PRODUCTS_IMAGE_PADDING' => ((PRODUCT_IMAGE_THUMBNAIL_HEIGHT + 8) - $array['products_image_h'])/2,
'PRODUCTS_IMAGE_ALT' => $array['gm_alt_text'],
'PRODUCTS_LINK' => $gm_product_link,
'PRODUCTS_PRICE' => $products_price['formated'],
'PRODUCTS_TAX_INFO' => $gm_tax_info,
'PRODUCTS_SHIPPING_LINK' => $gm_shipping_link,
'PRODUCTS_BUTTON_BUY_NOW' => $buy_now,
'GM_PRODUCTS_BUTTON_BUY_NOW_URL' => $gm_buy_now_url,
'GM_PRODUCTS_BUTTON_BUY_NOW' => $gm_buy_now,
'PRODUCTS_SHIPPING_NAME' => $shipping_status_name,
'PRODUCTS_SHIPPING_IMAGE' => $shipping_status_image,
'PRODUCTS_DESCRIPTION' => $array['products_description'],
'PRODUCTS_EXPIRES' => $array['expires_date'],
'PRODUCTS_CATEGORY_URL' => $array['cat_url'],
'PRODUCTS_SHORT_DESCRIPTION' => $array['products_short_description'],
'PRODUCTS_FSK18' => $array['products_fsk18'],
'GM_FORM_ACTION' => xtc_draw_form('gm_add_to_cart_'.$array['products_id'], xtc_href_link('index.php', 'action=buy_now&BUYproducts_id=' . $array['products_id'] . $gm_cat_search, 'NONSSL', true, true, true), 'post', 'onsubmit="return gm_quantity_check_listing(\'' . $array['products_id'] . '\')"'),
'FORM_DATA' => $t_form_array,
'QTY_DATA' => $t_qty_array,
'PRODUCTS_Quantity_x' => $array['products_quantity'],
'GM_FORM_END' => '</form>',
'GM_PRODUCTS_QTY' => $gm_qty,
'GM_PRODUCTS_STOCK' => $gm_products_stock,
'PRODUCTS_META_DESCRIPTION' => $array['products_meta_description'],
'PRODUCTS_WEIGHT' => gm_prepare_number((double)$array['products_weight'], $xtPrice->currencies[$xtPrice->actualCurr]['decimal_point']),
'SHOW_PRODUCTS_WEIGHT' => $array['gm_show_weight']);
return $t_data_array;
// EOF GM_MOD
Inside the html the following code is given
<span class="label">{$module_data.PRODUCTS_Quantity_x}<span>
I hope you can help me out here
thanks in advance
You can do this 2 way:
1) First way:
You simple use in Smarty the following code with added string_format:
<span class="label">{$module_data.PRODUCTS_Quantity_x|string_format:"%d"}<span>
2) Second way:
You do whatever you need in PHP and assign desired value in PHP.
So in PHP you can change line:
'PRODUCTS_Quantity_x'=> $array['products_quantity'],
into
'PRODUCTS_Quantity_x'=> (int) $array['products_quantity'],
and then in Smarty you use the same code as you used earlier (without string_format):
<span class="label">{$module_data.PRODUCTS_Quantity_x}<span>

PHP CodeIgniter Batch Insert Not Accepting My Array

I'm unable to get the following code to work, and it has something to do with the forming of the array. The array is actually build after a foreach() loop runs a few times, then I want to batch insert, but it comes up malformed. Why?
foreach ($results as $r) {
$insert_array = array(
'ListingRid' => $r['ListingRid'],
'StreetNumber' => $r['StreetNumber'],
'StreetName' => $r['StreetName'],
'City' => $r['City'],
'State' => $r['State'],
'ZipCode' => $r['ZipCode'],
'PropertyType' => $r['PropertyType'],
'Bedrooms' => $r['Bedrooms'],
'Bathrooms' => $r['Bathrooms'],
'YearBuilt' => (2011 - $r['Age']),
'Status' => $r['Status'],
'PictureCount' => $r['PictureCount'],
'SchoolDistrict' => $r['SchoolDistrict'],
'ListedSince' => $r['EntryDate'],
'MarketingRemarks' => $r['MarketingRemarks'],
'PhotoUrl' => (!empty($photo_url) ? $photo_url : 'DEFAULT'),
'ListingAgentFirstName' => $r['ListingAgentFirstName'],
'ListingAgentLastName' => $r['ListingAgentLastName'],
'ContactPhoneAreaCode1' => (!empty($a['ContactPhoneAreaCode1']) ? $a['ContactPhoneAreaCode1'] : 'DEFAULT'),
'ContactPhoneNumber1' => (!empty($a['ContactPhoneNumber1']) ? $a['ContactPhoneNumber1'] : 'DEFAULT'),
'ListingOfficeName' => (!empty($r['ListingOfficeName']) ? $r['ListingOfficeName'] : 'DEFAULT'),
'OfficePhoneComplete' => (!empty($o['OfficePhoneComplete']) ? $o['OfficePhoneComplete'] : 'DEFAULT'),
'last_updated' => date('Y-m-d H:i:s')
);
$insert[] = $insert_array;
}
$this->db->insert_batch('listings', $insert);
Here's the errors:
A PHP Error was encountered
Severity: Warning
Message: array_keys() [function.array-keys]: The first argument should
be an array
Filename: database/DB_active_rec.php
Line Number: 1148
A PHP Error was encountered
Severity: Warning
Message: sort() expects parameter 1 to be array, null given
Filename: database/DB_active_rec.php
Line Number: 1149
Any ideas? Thanks!
I've reduced your code to the bare minimum and it seems to work.
$i = 0;
while ($i <= 10) {
$insert_array = array(
'code' => 'asd'
);
$insert[] = $insert_array;
$i++;
}
$this->db->insert_batch('group', $insert);
You should check the elements of the array, comment them all and de-comment them one by one until you got the culprit.
Looks like you need to wrap your array in a second array. You're supposed to provide an array of row arrays.
$insert_array = array(array(...));

odd errors in php array

I am trying to json encode an array,it does encode but i get lots of errors:
$products = array( array( Title => "rose",
Price => "1.25,1.31,1.54,1.39",
Type => "dropdown"
),
array( Title => "daisy",
Price => "0.75",
Type => "text_field",
),
array( Title => "orchid",
Price => "1.15",
Type => "text_field"
)
);
echo json_encode($products);
I get the following errors.
Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 2
Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 3
Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 4
Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 6
Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 7
Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 8
Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 10
Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 11
Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 12
You need to quote the keys. Without quotes, they're constants. The interpreter is guessing what you mean, but you should change it to avoid the notice.
$products = array( array( "Title" => "rose",
"Price" => "1.25,1.31,1.54,1.39",
"Type" => "dropdown"
),
you must use quotation mark for STRING keys in arrays. Your code with changes is shown below:
<?php $products = array( array( 'Title' => "rose",
'Price' => "1.25,1.31,1.54,1.39",
'Type' => "dropdown"
),
array( 'Title' => "daisy",
'Price' => "0.75",
'Type' => "text_field",
),
array( 'Title' => "orchid",
'Price' => "1.15",
'Type' => "text_field"
)
); echo json_encode($products);
Additional information about arrays in php you will find here PHP: Arrays
put quotes around the array key names
$products = array( array( 'Title' => "rose",
'Price' => "1.25,1.31,1.54,1.39",
'Type' => "dropdown"
),
array( 'Title' => "daisy",
'Price' => "0.75",
'Type' => "text_field",
),
array( 'Title' => "orchid",
'Price' => "1.15",
'Type' => "text_field"
)
);
echo json_encode($products);
array( array( 'Title' => "rose",
'Price' => "1.25,1.31,1.54,1.39",
'Type' => "dropdown"
),
array( 'Title' => "daisy",
'Price' => "0.75",
'Type' => "text_field",
),
array( 'Title' => "orchid",
'Price' => "1.15",
'Type' => "text_field"
)
);
You might be confusing javascripts object notation syntax with PHP here, like the other answers have suggested, wrapping the array keys in quotes (so that they're passed in as strings) will sort out your problem.
It might be worth reading up on PHP Constants to better understand the error message you've been given: http://php.net/manual/en/language.constants.php
I came across the exact same problem and after staring at the PHP5 manual page for arrays it eventually clicked. Here is what I found out:
This line
If ($showallresult[Composer] == "") $showallresult[Composer] = "?";
will cause that notice to show.
I also use this line in my code
print ("<TD ALIGN=CENTER VALIGN=TOP>$showallresult[Composer]</TD>\n");
When I wrap the array key in single quotes in each line as such
If ($showallresult['Composer'] == "") $showallresult['Composer'] = "?";
print ("<TD ALIGN=CENTER VALIGN=TOP>$showallresult['Composer']</TD>\n");
I get a parse error on the second line, but the first line appears to be fine. Looking at http://us2.php.net/manual/en/function.array.php and there Example #4 the answer is right there. When accessing array values within a double quoted string you have to enclose the array value construct in curly braces (mustaches). As it turns out, this is how it is correct:
If ($showallresult['Composer'] == "") $showallresult['Composer'] = "?";
print ("<TD ALIGN=CENTER VALIGN=TOP>{$showallresult['Composer']}</TD>\n");
Oddly, this works as well without throwing parse errors or notices...welcome to the logic of PHP:
If ($showallresult['Composer'] == "") $showallresult['Composer'] = "?";
print ("<TD ALIGN=CENTER VALIGN=TOP>$showallresult[Composer]</TD>\n");
Rather bizarre that both lines work fine and generate the expected result. While the no-single-quote-no-curly-braces notation works I do suggest to go with how it seems to be correct and use curly braces and single quotes within a string.
In any case, reading the docs and mulling over it some time fixed it for me. And yes, sadly, it's all there right in the manual!

Categories