I am making a feedback form, and I have it set up so that in submission1.php, it will gather the variable from the textarea from the index.php. It then pushes it into a variable. I then include submission1 in seefeedback.php but when I try to print it out I get NULL. What am I doing wrong?
Every php page you run is a process on it's own which does not have variables.
will never work in
seefeedback.php. The variable
$feedback is not set because the page has no idea it exists.
You need a way to communicate between pages. This can be done through cookies as you tried, but it's better to either use:
- the url (as in
- a session variable
$_SESSION['feedback'] = ...
also test all your code using a php linter, e.g. https://phpcodechecker.com/
@blonkm Thanks. Right now, I'm just going to make everything on a single page, ignore the other things. It will push it into an array, and with the cookies, when I reload the page to login, it will still have it. Although I can think of some flaws now. Can you point them out? Also, I don't think session works. Or I need to know how to use it. Also, what do you mean by URL? like what would I store in it? Also, I want to get everyone's feedback and store it in a single array.
After what you said, I realize I don't think I can do it, since every time the page reloads, only that feedback that they submitted is entered, is there a way I can cross-session, like take something from someone's session and add it into my own session so I can see everyone's? Thanks.
@Baconman321 What you need for that is a database. That seems too far ahead for you right now. I would stick to one page and get everything working and then start thinking about learning about a database.
Remember that a web page is just a page. Users connecting to it will not magically know about other users. A database is a separate entity that can connect to your web server.
USERS <===> WEB SERVER <===> DATABASE
Users will never see the database. The Web server has a really short memory, and can only work with one user at a time.
Maybe you need to put the data into a list. Could you print out the feedback after I submit it?
BTW i love phantom forces
@Egghead21 If I submit the feedback, all it does is just print NULL. That's why I'm pushing it into a variable, because the global variable only holds the information temporarily, or so it seems. I am trying to access it and hold it in a variable.
I need to access a variable from another folder using include, but it's not letting me access the variables.
@Baconman321 Global variables don't allow you to pass information between folders. Create a new folder, and make the variable there
folder1's name will be config.
So in folder 1(with the variable):
feedback = ''
and then in your input section:
config.feedback = input(': ')
This would set config.feedback- the feedback variable from config- to the input. Then, you can display it by using-
This should work.