Errors ,errors

  if(!empty($_POST['images'])){
$images= $_POST['images'];
}
 
  $images = $_FILES['images']['name'];
{
  $target = 'images/'.basename($images);

 
}

Notice: Undefined index: images in C:\xampp\htdocs\h\l\cv\blog-post-dark.php o

Notice: Undefined index: images in C:\xampp\htdocs\h\l\cv\blog-post-dark.php

i am getting errors too many like that is any way that can get rid of it.

And you did not even have a research for this very specific, already millionfold answered error message? Just stop using undefined indexes, check them with isset before.

i did

Do you think this is a helpful message for anybody? You did what, which way, expecting which result, and got which result?

1 Like

You did what? You certainly didn’t use isset()

1 Like

i tried too many ways no result just error

What do you get if you echo the value of $_FILES['images']['name'] ?

nothing

and what value would you expect it to have?

image

  if(!empty($_POST['images'])){
$images= $_POST['images'];
}
 
  $images = $_FILES['images']['name'];
{
  $target = 'images/'.basename($images);

 
}

… I don’t… this code shouldnt even compile. what is the second set of braces for? What do they attach to? Why are we redefining $images outside of the if?

we need define image and problem will have solved

Do you have separate form fields, one for text or similar type and another for the upload file, but both called “images”? That seems to work in my quick test, but I can’t see that it’s a very good idea.

If you don’t, then you’re not testing the same things. If your only input called “images” is your “type=file” input, then it won’t appear in $_POST.

you got right two forms calling images,on different place that where spouse to be.One is calling for server another one in db text.

<offtopic>
PHP doesn’t care about braces, you can add as many redundant braces as you like

Case in point: https://3v4l.org/RBLPg

:man_shrugging:

This can cause very nasty errors, like

for ($i = 0; $i < 10; $i++); // <-- note the ; at the end
{
    echo $i;
}
// will just echo 9 once

</offtopic>

i dont have loops

That’s why my post is in <offtopic> - meaning I’m replying to something in the thread somebody said, not to your question, but still might be interesting.

4 Likes

OK, then your code makes less sense. If the $_POST variable is set, then you assign it to $images. Then, regardless of whether it was set or not, you overwrite $images with another value, without checking whether it exists or not. What’s the point of the first assignment if you’re going to immediately overwrite it?

2 Likes

Maybe missing an else clause?

I was thinking the exact same thing. The whole logic doesn’t make sense. If the logic is supposed to be for uploading a file and allowing the file to have a description, then the way you are going about it is wrong. Like droopsnoot says, you overwrite the value of whatever gets posted with the uploaded file’s name. They both should have different variables. If this isn’t your intention, then having a field for posting makes no sense. If this is supposed to be for uploading only files, then it makes no sense to use $_POST.

I am going to advise you on something critical that can save you and other headaches. Before you want to make any new files or new ideas, plan it out first. Brainstorm on how it’s supposed to work because the way you are showing us now does not demonstrate that you have thought about how your files are going to work. It seems you are just throwing whatever you find on the internet in your files. Please stop doing this because I already told you twice from your other thread not to do this. Plan how your files are supposed to work before you do anything like this or you’ll always get stuck.