Why is my index undefined, and does it matter? [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 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']))

Related

PHP Notice: Undefined index section? [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 10 months ago.
I use the section, but this error occurs, in fact, it enters the site and everything is done correctly, but this error occurs behind the scenes. What is the solution?
PHP Notice: Undefined index: walletaddrass in /home/decent/public_html/user/presale.php on line 5
$id_wallet = $_SESSION["walletaddrass"];
The quantification is done as follows:
$_SESSION["walletaddrass"] = $id_wallet;
setcookie('logged-in','true', time() + 286400 , '/');
Please post the whole file where you are getting this error next time.
The issue is because you are trying to use $_SESSION["walletaddrass"] when it's not set, as you are setting it in the line below it.
You must first check if the session variable is set as follows:
if (isset($_SESSION['walletadrass'])) {
$id_wallet = $_SESSION["walletaddrass"];
$_SESSION["walletaddrass"] = $id_wallet; setcookie('logged-in','true', time() + 286400 , '/');
}

How to get rid of undefined index in this situation [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)
PHP check value against multiple values with OR-operator
(3 answers)
Closed 4 years ago.
Hi,
I have this code:
if($_GET['s']=="page1" || $_GET['s']=="page2" || $_GET['s']=="page3") {
dosomething();
}
and I get this error: : Undefined index: s in
Which I can dismiss only by adding this line:
$_GET['s']="";
but then this wont execute the code correctly since $_GET['s'] is not supposed to have any initial value. How do I fix this other than disabling the notices and errors?
Thank you.
You can check your $_GET['s']
if(isset($_GET['s'])) {
// your code goes here...
}
isset() is used to check if the index exists.

Undefined index: command in C:\wamp64\www\WSMshop\products.php on line 5 [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 5 years ago.
if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
$pid=$_REQUEST['productid'];
addtocart($pid,1);
header("location:shoppingcart.php");
exit();
}
Notice: Undefined index: command in C:\wamp64\www\WSMshop\products.php on line 5
and that's the error, i do what i know can fix it, but nothing happen. Please help me. im still newbie in this. TIA
Since too little code is provided - my suggestion is to simply make additional check whether the 'command' is being submit by changing the if statement to:
if(isset($_REQUEST['command']) && $_REQUEST['command']=='add' && $_REQUEST['productid']>0){
Cheers!

PHP Problems related to Undefined index error [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.
Can you help me with this errors. I am actually trying to generate an invoice. However, my generated invoice having some problems as you can see as the image below.
Here is the image of my coding.
$oid = ( isset($_GET['oid']) ) ? $_GET['oid'] : null;
Also I believe line 38 should come before line 37. bindParam calls a variable defined after it.
You use variable $oid which it's data is $_GET['oid'], in your query before you actually declare/store data to it.
Move line 38 -> $oid = $_GET['oid']; after opening try/catch, that means to line 29, before stating the query. You should implement #fie answer too, to be sure that $oid is not null and that data actually exists.
Also something is wrong with line 73 but we can't see it.

undefined index: text (opencart) [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.
So I receive this message when on my category pages:
Notice : Undefined index: text in /home/thespace/public_html/vqmod/vqcache/vq2-catalog_view_theme_spacec_template_product_category.tpl on line 13 ยป Meteorite Jewellery
Though I can't see the problem in that particular line of code:
<?php echo $breadcrumb['separator']; ?><span itemprop="title"><?php echo $breadcrumb['text']; ?></span>
Am I missing something here?
The message is pretty clear: "Undefined index: text", you don't have the index "text" in your variable. In that case $breadcrumb['text'] does not exists.
You can try a var_dump($breadcrumb) to debug this variable.
As you can see the doc, this function will print in the page the parameter given. I suggested to you to use it, just so you could see that the "text" was indeed missing. Now you must see why this index no longer exist or if it even existed before. We can't help you with the current info, though.

Categories