Undefined Variable in Laravel PHP [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 4 years ago.
I'm new to Laravel and I'm very struggling with it. Please help me. I want to retrieve data from database to display on web page. But It alert message:
ErrorException (E_ERROR)
Undefined variable
display.blade.php
#foreach ($displays as $display)
{{ $display->first_name }}
{{ $display->last_name }}
#endforeach
DisplayController.php
public function index(){
$displays = Info::where('id', 1)->get();
return view('display', compact("display"));
}

you have a typo in your displaycontroller.php
return view('display', compact("display"));
should be
return view('display', compact("displays"));
you are missing the s behind display

Related

undefined index while update in php issue [PLEASE HELP] [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 had a problem in this line, because the error message tell me theres an undefined index:
$strSQL = " UPDATE place SET
rating_value = '".$_POST["rating_value"]."'
WHERE place_id = '".$_POST["place_id"]."'
";
pls help me if you have a solution. thanks
Do you check your variables before do the request like :
if( !empty($_POST["rating_value"]) && !empty($_POST["place_id"]) )
{
// your request
} else {
echo("error");
}

PHP URI values showing up as undefined [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.
What I want to do is echo the value of $test on my page, through the uri. I know I'm doing something wrong, but I can't figure out what.
Code:
<?php echo $test?>
URL:
localhost/testMap/test.php?test=hallo
You can get the value of url with a get, and store it in the variable $test and then echo that out.
$test = $_GET['test'];

Undefined Index in PHP Code [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 getting an undefined index error on this line of code:
switch ($_REQUEST["___p"])
I think I would need to declare the variable. What would I change the above line to?
Either make sure exists beforehand with isset() or just ignore it:
switch (#$_REQUEST["___p"])

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

Notice: Undefined index: n variable integer [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 7 years ago.
Notice: Undefined index: n in C:\Users\Marseille\Desktop\Activation
W7\UwAmp\www\quezzer\question.php on line 5
this is a code tiped at question.php
$number = (int) $_GET['n'];
why i have this error! i have not understand!
Since this is a get variable you're using, from what I understand is that you maybe trying to run the script questions.php directly. Therefore no get variables are set, try
localhost/yourfolder/questions.php?n=5

Categories