/    Sign up×
Community /Pin to ProfileBookmark

Help with undefined variable error

I am trying to display some text “THIS IS A TEST” on the html page.

I am getting this error:

Notice: Undefined variable: text1 in /home/public_html/themes/videos/content.html on line 23

line 23 is this:

[CODE]
<div class=”test”><font color=”#696969″ font size=”3″ face=”Arial”>HELLO<?php echo $text1;?></font>
[/CODE]

The php file, related to the html page, shows this (partially):

[CODE]
$text1 = “THIS IS A TEST”;
$cateogry_id = ”;
$videos = array();
if ($page == ‘trending’) {
$title = $lang->trending;
$db->where(‘privacy’, 0);
$videos = $db->where(‘time’, time() – 172800, ‘>’)->orderBy(‘views’, ‘DESC’)->get(T_VIDEOS, $limit);
}

else if ($page == ‘latest’) {
$title = $lang->latest_videos;
echo “$text1”;
$db->where(‘privacy’, 0);
$videos = $db->orderBy(‘id’, ‘DESC’)->get(T_VIDEOS, $limit);
}

else if ($page == ‘top’) {
$title = $lang->top_videos;
$db->where(‘privacy’, 0);
$videos = $db->orderBy(‘views’, ‘DESC’)->get(T_VIDEOS, $limit);
}

else if ($page == ‘category’) {
if (!empty($_GET[‘id’])) {
if (in_array($_GET[‘id’], array_keys($categories))) {
$cateogry = PT_Secure($_GET[‘id’]);
$title = $categories[$cateogry];
$cateogry_id = “data-category=’$cateogry'”;
$db->where(‘privacy’, 0);
$videos = $db->where(‘category_id’, $cateogry)->orderBy(‘id’, ‘DESC’)->get(T_VIDEOS, $limit);
} else {
header(“Location: ” . PT_Link(‘404’));
exit();
}
}
}
[/CODE]

what do I need to correct to remedy this error?

Any help is appreciated.

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@rootFeb 17.2019 — not helpful because you show one line of the supposed error and a bunch of PHP that shows no relationship as to how the PHP is added to the HTML and where the HTML sits in relation to the PHP in the realms of the parser.

if your $text one appears after the first use, then yes, it will error out.

Beyond that, I can't see why a variable would not exist if it has been declared.
Copy linkTweet thisAlerts:
@cootheadFeb 17.2019 — > @chrisjchrisj#1601054

**[color=#069]

<font color="#696969" font size="3" face="Arial">[/color]
**


>[color=navy]

_"**Do not use this element ! **

Though once normalized in HTML 3.2, it was deprecated

in HTML 4.01, at the same time as all elements related to

styling only, then obsoleted in HTML5."_
[/color]


**Source** :-

[url=https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font#Summary][color=#069]The font element and it's attributes[/color][/url]

HTML 4 became a standard in April 1998.

It’s update, HTML 4.0.1, was published in December 1999.

_coothead_
Copy linkTweet thisAlerts:
@ginerjmFeb 17.2019 — As others have pointed out - you show us an error that by itself is unflawed. BUT then you show us some TOTALLY UNRELATED CODE and want us to give you an answer.

How about showing us where line 23 (you have shown us "line 1") exactly exists in that block of code. BTW - do you think that whole block of code is really needed to solve this riddle?

And - yes. Whatever reference guide you are using to learn your html you should throw out. There are plenty of newer more current ones out there, online and in the stores.
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 17.2019 — Thanks for your replies. Sorry for the truncated code posting.

There is a php file (where I added line 35 and line 39):

[CODE]
<?php

declare( strict_types=1);
// these should be set in PHP.ini
error_reporting(-1); // set maximum errors
ini_set('display_errors' , 'true');


if (empty($_GET['page'])) {
header("Location: " . PT_Link('404'));
exit();
}
$page = PT_Secure($_GET['page']);
$limit = 20;
$pt->rss_feed = false;
$pt->exp_feed = true;
$pages = array(
'trending',
'category',
'latest',
'top'
);

if (!in_array($page, $pages)) {
header("Location: " . PT_Link('404'));
exit();
}

if (!empty($_GET['feed']) && $_GET['feed'] == 'rss') {
$limit = 50;
$pt->rss_feed = true;

}

$text1 = 'THIS IS A TEST';
$cateogry_id = '';
$videos = array();
if ($page == 'trending') {
$text1 = 'trending';
$title = $lang->trending;
$db->where('privacy', 0);
$videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'latest') {
$title = $lang->latest_videos;
$db->where('privacy', 0);
$videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'top') {
$title = $lang->top_videos;
$db->where('privacy', 0);
$videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'category') {
if (!empty($_GET['id'])) {
if (in_array($_GET['id'], array_keys($categories))) {
$cateogry = PT_Secure($_GET['id']);
$title = $categories[$cateogry];
$cateogry_id = "data-category='$cateogry'";
$db->where('privacy', 0);
$videos = $db->where('category_id', $cateogry)->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
} else {
header("Location: " . PT_Link('404'));
exit();
}
}
}

use BhaktarazRSSGeneratorItem;
use BhaktarazRSSGeneratorFeed;
use BhaktarazRSSGeneratorChannel;


//Export rss feed
if ($pt->rss_feed) {
$rss_feed_xml = "";
$fl_rss_feed = new Feed();
$fl_rss_channel = new Channel();


$fl_rss_channel
->title($pt->config->title)
->description($pt->config->description)
->url($pt->config->site_url)
->appendTo($fl_rss_feed);

if (is_array($videos)) {
foreach ($videos as $feed_item_data) {
$feed_item_data = PT_GetVideoByID($feed_item_data, 0, 0, 0);
$fl_rss_item = new Item();
$fl_rss_item
->title($feed_item_data->title)
->description($feed_item_data->markup_description)
->url($feed_item_data->url)
->pubDate($feed_item_data->time)
->guid($feed_item_data->url,true)
->media(array(
'attr' => 'url',
'ns' => 'thumbnail',
'link' => PT_GetMedia($feed_item_data->org_thumbnail)))
->appendTo($fl_rss_channel);
}
}

header('Content-type: text/rss+xml');
echo($fl_rss_feed);
exit();
}


$html_videos = '';
if (!empty($videos)) {
foreach ($videos as $key => $video) {
$video = PT_GetVideoByID($video, 0, 0, 0);
$html_videos .= PT_LoadPage('videos/list', array(
'ID' => $video->id,
'VID_ID' => $video->id,
'TITLE' => $video->title,
'VIEWS' => $video->views,
'VIEWS_NUM' => number_format($video->views),
'USER_DATA' => $video->owner,
'THUMBNAIL' => $video->thumbnail,
'URL' => $video->url,
'TIME' => $video->time_ago,
'DURATION' => $video->duration
));
}
}

if (empty($videos)) {
$html_videos = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_for_now . '</div>';
}
$pt->videos_count= count($videos);
$pt->page = $page;
$pt->title = $title . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword = @$pt->config->keyword;
$pt->content = PT_LoadPage('videos/content', array(
'TITLE' => $title,
'VIDEOS' => $html_videos,
'TYPE' => $page,
'CATEGORY_ID' => $cateogry_id
));

[/CODE]



and an html file ( I added line 23):


[CODE]
<div class="wo_about_wrapper_parent">
<div class="wo_about_wrapper">
<div class="hero hero-overlay" style="background-color: #033d5d;">
<div class="container">
<h1 class="text-center"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video"><polygon points="23 7 16 12 23 17 23 7"></polygon><rect x="1" y="5" width="15" height="14" rx="2" ry="2"></rect></svg> {{TITLE}}</h1>
</div>
</div>
<svg id="wave" viewBox="0 0 1440 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(0.000000, -564.000000)" fill="#033d5d"><g id="Head-background" transform="translate(-168.000000, -346.000000)"><g id="waves-background" transform="translate(888.000000, 934.000000) scale(-1, 1) translate(-888.000000, -934.000000) translate(168.000000, 910.000000)"><path d="M0,14.60779 C101.722445,4.7613277 195.244576,-4.14113188e-14 429,-2.84217094e-14 C732,-1.97619698e-14 798,45.6756592 1089,45.6756592 C1245.83848,45.6756592 1364.64602,29.5028807 1440,14.5904096 C1440,14.60779 1440,48 1440,48 L0,48 C0,48 0.0410082206,34 0,14.60779 Z" id="Path-3-Copy"></path></g></g></g></g></svg>
</div>
</div>
<div class="content pt_shadow pt_page_margin" style="padding-top: 25px;">
<div class="col-md-12">

<div class="upload-head">
<div style="float: right;">
<button class="btn btn-main" data-action="multuple-buy-video" onclick="PT_MultipleBuyVideo();">View all selected</button>
</div>
<h4><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg></h4>
<hr>
</div>
<div class="test"><font color="#696969" font size="3" face="Arial">HELLO<?php echo $text1;?></font>
</div>
<div class="videos-latest-list row">
{{VIDEOS}}
</div>
<?php if ($pt->videos_count > 1) { ?>
<div class="watch-video-show-more desc load-more" data-type="{{TYPE}}" {{CATEGORY_ID}}>
{{LANG show_more}}
</div>
<?php } ?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
[/CODE]


yes, I'm aware of the <font> code is old. I don't use it, but in this case I was in a hurry to test this, and added it quickly just to see the text in a color.

Any way I am still seeing the error on the html page:

Notice: Undefined variable: text1 in /home/public_html/themes/videos/content.html on line 23

Any additional guidance to remedy this error is appreciated.
Copy linkTweet thisAlerts:
@ginerjmFeb 17.2019 — Good luck. I have no idea what you are presenting. Would you if I posted so much code that had no comments or enough focus on something that would help to make sense?

PS - what is the significance of the two well-disguised lines 35 & 39 that you added, wherever they are?
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 17.2019 — Thanks for your reply.

Line 35 which is $text1 ='THIS IS A TEST' and line 39 which is $text1='trending' is my attempt at creating a new variable, assigning text that I want to display on Line 23 which is HELLO<?php echo $text1;?> of the html page. Any other help will be welcomed.



[CODE]
$text1 = 'THIS IS A TEST';
$cateogry_id = '';
$videos = array();
if ($page == 'trending') {
$text1 = 'trending';
$title = $lang->trending;
$db->where('privacy', 0);
$videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
}
[/CODE]
Copy linkTweet thisAlerts:
@NogDogFeb 17.2019 — > @chrisjchrisj#1601060 and an html file ( I added line 23):

How does the "html file" get called? Does it include() or require() a separate file where you are actually setting that variable, before that line gets executed? If so, are you using require() or require_once() to include it, to make sure you get a fatal error if it's not loading for some reason?
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 17.2019 — Thanks for your reply and question 'how does the html file get called'.

This is at the bottom of the php code above:

[CODE]
$pt->content = PT_LoadPage('videos/content', array(
'TITLE' => $title,
'VIDEOS' => $html_videos,
'TYPE' => $page,
'CATEGORY_ID' => $category_id,
[/CODE]


does that look like that code loads/calls the html page?

I look forward to any additional help
Copy linkTweet thisAlerts:
@NogDogFeb 18.2019 — @chrisjchrisj#1601065

Presumably it loads that file, since you're getting the error in it, but I'm guessing maybe you need to pass $text1 into the array that is supplied to that PT_loadPage() function, and then reference it within the page the same way those other values are. (Something like $some_array_name['TITLE'], for the $title value, for example?)
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 18.2019 — Thanks so much for your reply. I really appreciate it.

Based on your suggestion, I tried this in the php:


<i>
</i>$text1 = 'THIS IS A TEST';
$category_id = '';
$videos = array();

if ($page == 'trending') {
$title = $lang-&gt;trending;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;where('time', time() - 172800, '&gt;')-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text1 = 'TEXT';
}

along with this:

$pt-&gt;content = PT_LoadPage('videos/content', array(
'TITLE' =&gt; $title,
'VIDEOS' =&gt; $html_videos,
'TYPE' =&gt; $page,
'CATEGORY_ID' =&gt; $category_id,
'TEXT' =&gt; $text1



to try to pass $text1 into the array, and still see the same error. Any guidance into what I have incorrect here, regarding 'passing $text1 into the array' is appreciated.
Copy linkTweet thisAlerts:
@NogDogFeb 18.2019 — Looks like your app is using some sort of template system that uses "{{...}}" to output one of those values, e.g.:
<i>
</i>data-type="{{TYPE}}"

So, my guess is that once you've added that assignment to the 'TEXT' key, you can just do something like this, not even using `<?php...?> tags:
<i>
</i>&lt;p&gt;Here's my text: &lt;strong&gt;{{TEXT}}&lt;/strong&gt;&lt;/p&gt;
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 18.2019 — Thanks so much for your reply. I really appreciate it.

Based on your suggestion, I tried this in the php:


<i>
</i>$text1 = 'THIS IS A TEST';
$category_id = '';
$videos = array();

if ($page == 'trending') {
$title = $lang-&gt;trending;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;where('time', time() - 172800, '&gt;')-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text1 = 'TEXT';
}

along with this:

$pt-&gt;content = PT_LoadPage('videos/content', array(
'TITLE' =&gt; $title,
'VIDEOS' =&gt; $html_videos,
'TYPE' =&gt; $page,
'CATEGORY_ID' =&gt; $category_id,
'TEXT' =&gt; $text1


and have this in the html:

<i>
</i>&lt;div class="test"&gt;HELLO{{TEXT}}&lt;/div&gt;


and that successfully displays:

"HELLO THIS IS A TEST"

Thanks for the help.

I am interested in a little more help, if you are so inclined.

My initial intention was to display unique text, when each of three pages appears. When if ($page == 'trending')

"unique text 1" displays. if ($page == 'latest') than "unique text 2" displays, and if ($page == 'top') than "unique text 3" displays. But, then I got that undefined variable error. Now, I'm trying to have the unique text display again.

I just tried this:

<i>
</i>$text1 = 'THIS IS A TEST';
$text2 = 'THIS IS TEST 2';
$category_id = '';
$videos = array();

if ($page == 'trending') {
$title = $lang-&gt;trending;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;where('time', time() - 172800, '&gt;')-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text1 = 'TEXT';
}


else if ($page == 'latest') {
$title = $lang-&gt;latest_videos;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;orderBy('id', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text2 = 'TEXT2';
}

along with this:

$pt-&gt;content = PT_LoadPage('videos/content', array(
'TITLE' =&gt; $title,
'VIDEOS' =&gt; $html_videos,
'TYPE' =&gt; $page,
'CATEGORY_ID' =&gt; $category_id,
'TEXT' =&gt; $text1,
'TEXT2' =&gt; $text2




and this in the html code:

<i>
</i>&lt;div class="test"&gt;HELLO{{TEXT}}{{TEXT2}}&lt;/div&gt;


but, it shows me this on all three displayed pages:

HELLOTHIS IS A TESTTHIS IS TEST 2

Any guidance as to how to display unique text, when each unique page is loaded, will is appreciated.
Copy linkTweet thisAlerts:
@NogDogFeb 18.2019 — How about in the if/elseif on $page you just assign the desired value to $text, and then just pass that to a single 'TEXT' array key, and use {{TEXT}} where desired?
<i>
</i>if ($page == 'trending') {
$title = $lang-&gt;trending;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;where('time', time() - 172800, '&gt;')-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text = 'Trending text here';
}
elseif ($page == 'latest') {
$title = $lang-&gt;latest_videos;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;orderBy('id', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text = 'Latest text here';
}

$pt-&gt;content = PT_LoadPage('videos/content', array(
'TITLE' =&gt; $title,
'VIDEOS' =&gt; $html_videos,
'TYPE' =&gt; $page,
'CATEGORY_ID' =&gt; $category_id,
'TEXT'=&gt; $text
);
Copy linkTweet thisAlerts:
@chrisjchrisjauthorFeb 18.2019 — Thanks again for your reply.

I've tried this:

<i>
</i>$text = '';
$category_id = '';
$videos = array();

if ($page == 'trending') {
$title = $lang-&gt;trending;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;where('time', time() - 172800, '&gt;')-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text = 'trending text here';
}

else if ($page == 'latest') {
$title = $lang-&gt;latest_videos;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;orderBy('id', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text = 'Latest text here';
}

else if ($page == 'top') {
$title = $lang-&gt;top_videos;
$db-&gt;where('privacy', 0);
$videos = $db-&gt;orderBy('views', 'DESC')-&gt;get(T_VIDEOS, $limit);
$text = 'Top text here';
}


along with this:


$pt-&gt;content = PT_LoadPage('videos/content', array(
'TITLE' =&gt; $title,
'VIDEOS' =&gt; $html_videos,
'TYPE' =&gt; $page,
'CATEGORY_ID' =&gt; $category_id,
'TEXT' =&gt; $text



and the html file page has this:

&lt;div class="test"&gt;HELLO{{TEXT}}&lt;/div&gt;


Yet, all that is displayed is: HELLO

Any additional guidance is appreciated.
×

Success!

Help @chrisjchrisj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...