PHP Problems related to Undefined index error [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.
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.

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 , '/');
}

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']))

i got a error on php file for my school project [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.
Notice: Undefined variable: upid in C:\wamp\www\probeer\opvragen.php on line 112
Call Stack
# Time Memory Function Location
1 0.0007 264840 {main}( ) ..\opvragen.php:0
line 112
echo 'Update</td></tr>';
To simply answer your question the variable $upid is not defined, just like your error says.
Your are trying to echo out the content of the variable $upid right here:
?upid='.$upid.'
So somewhere above line 112 in your file, $upid should be assigned a value, but it isn't.
If you on line 111 do this:
$upid = "Test";
Then your script wont throw the error, but you have to actually assign the value you want for it, so its time to look at your code where you are supposed to define it.

Undefined Index Error in PHP Image Upload [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 9 years ago.
Can someone tell me what is wrong with this line of code? I am getting an error (yet the the page still functions properly despite the error)
Error:
"Notice: Undefined index: picture in C:\wamp\www\pplogin\members.php on line 180"
Here is the code:
179 $target = "user_images/fs/";
180 $target = $target . basename($_FILES['picture']['name']);
Like I said earlier despite the error the image gets uploaded to the destination and the image name is saved to my MySQL database.
I've been scratching my head for a while now...
$target = !empty($_FILES['picture']['name']) ? $target.basename($_FILES['picture']['name']) : false;
A file with id
picture
doesn't exist.
Use
isset()
to make sure It's set.
You can also use the ternary operator:
$img = isset($_FILES['picture']) ? $_FILES['picture'] : null;
Or something like that :)

fixing undefined index notice [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 9 years ago.
I'm getting an undefined index notice, but can't figure out how to fix it.
Notice: Undefined index: id in /home/jharvard/vhosts/localhost/html/book_details.php on line 10
This is the code that's having problems:
// query for the listing
$listing = query("SELECT name, author, id, edition, price, course, date FROM books WHERE submission = ?", $_GET["submission"]);
// query for the email of the seller
$seller = query("SELECT email FROM users WHERE id = ?", $listing["id"]);
Can anyone help? Thank you very much.
The problem is that the array returned from your first query, $listing doesn't have an element with the key id.
I suspect this would happen if there was no record in the database for whatever was passed in as the submission GET parameter. Hard to say for sure though without knowing how the query() function was written.

Categories