"Undefined variable" error in PHP Simple HTML DOM [duplicate] - php

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 last year.
I want to extract the information on this page using a script PHP Simple HTML DOM,
Here is part of the code I wrote:
$html = file_get_html('https://www.digikala.com/product/dkp-7475119/');
foreach ($html->find('p.color-900') as $e) {
$color = $e->outertext;
echo $color ;
break;
}
But unfortunately the output I receive is Undefined variable

As #Kevin Y said in his comment, you are searching for something that isn't there... yet.
Visit view-source:https://www.digikala.com/product/dkp-7475119/ and search for <p>
The page hasn't loaded the extra elements onto it yet like the <p> tag you are looking for. This is likely because the page is loading them in after-the-fact using JavaScript so you will need to find a way to get the html after the page has loaded its contents that are added in later.

Related

I'm getting syntax error when trying to send password in form [duplicate]

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 4 years ago.
I'm very new at php. I get these errors when I write these codes.
check to see if islem was passed in before trying to access it
if (isset($_POST['islem']) {
// your code here
}
Otherwise you won't be able to load the page up initially in order to submit the form. Also notice that I used _POST here, this is because you used the POST method in your form.
You are using the method POST in the form and getting the variables with GET
Either Try method : GET or try $_POST["islem"];

Why is my index undefined, and does it matter? [duplicate]

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 6 years ago.
When i press F12 and look at the warnings i see a message that says
Line 18: Undefined index: task_uid
I just dont really understand why it is undefined, considering that i did declare it, and then select it, in here:
<?php
session_start();
require ("../../../main/gerais/DBConn.php");
$task_uid = $_GET['task_uid'];
$proj_id = $_GET['proj_id'];
?>
This here comes three lines before the "Line 18" that is supposed to be the error, according to the console. Here is this Line:
<?php
if(!empty($_POST['proj_id'])||($_POST['task_uid']))
die("Invalid proj_id or task_uid.");
$query = "
SELECT pm.proj_id, pm.task_uid, etc etc etc...
?>
So why is it undefined? And, while i'm not sure if this question is answerable without context, but how much does it matter, considering this "task_uid" shows up in the URL, and considering it only showed up as a warning, not as a real error?
You need to use !empty on both variables:
if(!empty($_POST['proj_id'])||!empty($_POST['task_uid']))

PHP cookies to pass variables between two pages [duplicate]

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 6 years ago.
I am aware that I can use sessions and GET/ POST method but I would like to achieve this using cookies. My code on page1.php is :
$_COOKIE['varname'] = $id;
and on page2.php is:
$id = $_COOKIE['varname'];
I get the following notice on my browser: Undefined index $id
What is the problem with my code?
Try using setcookie('varname', $id) then
if (isset($_COOKIE['varname']){ echo $_COOKIE['varname']; }
To set a cookie you need to use setcookie(). And it has to be done prior to any output.
setcookie("mycookie", "myvalue" , $validtime); // validtime is a integer.

Individual profile page with PHP and MySQL [duplicate]

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 6 years ago.
I have a list of profiles, and i need to make the user able to select the individual profile in a link.
I found this question and tried to follow it, but it doesnt quite work as i hoped it would: Displaying a user profile page PHP
The file to display all profiles on the page looks like this:
foreach ($rows as $row) {
echo '<a class="viewProfile" href="user.php?id=' . $r['UID']. '"><button>View Profile</button></a>';
}
But when i click the link the UID doesn't get posted in the URL, and it just looks like this: domain/user.php?id=
Update: With help from you guys i got the UID posted into the URL. Thanks!
And as jothi stated $id=$_GET['id'];
That's because $r['UID'] is not defined. You are enumerating some $row, so I assume that you mean $row['UID'].
If it doesn't work, please, post the result of this line, just before you foreach ($rows as $row)
echo print_r($rows);

Undefined Variable title in Laravel [duplicate]

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 4 years ago.
This error I am getting in Laravel. Can I know what exactly can be the issue. I have spent my full day into this.
you should pass all your variables you use in view, if you use $title as a title for each page in your website you should pass it from your controller function to the view like this:
return View::make('home.index')->with('title', 'your title here');
and in your view you can make a condition to display public title to all pages don't have a title like this:
#if(isset($title)){{$title}} #else {{'Default title here'}} #endif
Check your Controller. If in controller variable $title is empty and you manipulate with it then you will get similar error.
your $title variable is null .
Make sure that $title is not null
try this in your blade
#if(isset($title)){{$title}}#endif

Categories