Undefined Index Error in PHP Image Upload [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 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 :)

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

Uploading file to server folder. - PHP [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 2 years ago.
So here is the code. I get error such as "Undefined index: fad in C:\wamp\www*imdone.php* on line ..."
But the link is - http://localhost/exercises.php?page=htmlex&get=imdone#container.
Hope i could explain barely
$folder = 'test/';
$uploadingfile = $folder . basename($_FILES['fad']['name']);
if (move_uploaded_file($_FILES['fad']['tmp_name'], $uploadingfile))
{
echo "Upload successfully.<br>";
} else {
echo "Upload unsuccesfully\n";
}
The 'fad' in the $_FILES['fad']['name'] is suppose to be the name of your input type=file field in the form. You should first double check with your form to confirm the name.

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.

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.

unnecessary notice from php [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)
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
recently i just configure my script with common script for entry data
while im trying to submit the data , the data is successful to submit . but there is something notice that bothering me , they say Notice: Undefined index: type in D:\xampp\htdocs\project\submit.php on line 7
and the line is
<?php
include 'includes/config.php';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$type=addslashes($_POST['type']); // this is line 7
$nama_barang=addslashes($_POST['nama_barang']);
$kategori=addslashes($_POST['kategori']);
$deskripsi=addslashes($_POST['deskripsi']);
im using xampp v.3.2.1 , it is possible the notice is from the xampp ?
thanks you guys im so glad for your answer :))
type (and other $_POST members) may not always be set so you should try and code to detect that.
e.g:
$type = (isset($_POST['type'])) ? addslashes($_POST['type']) : false;
The notice mentions that your $_POST array has no index type.
So you should check for it before you try to access it:
$type = ""; //you could set a default here
if(array_key_exists("type", $_POST))
$type = addslashes($_POST['type']);

Categories