I have a webpage that stores the user ID of someone who clicks a button on the page. Once the button is clicked, that user needs to be able to see content (just another button) that only that user can see. Other users on that page won't be able to see that button.
The problem I'm having is I don't know how to use that unique user ID, which is superglobal, to recognize on load what the user ID is, and how to execute if its the correct user, show the otherwise hidden inputs.
It is same problem that arised to me
You have two option to solve this problem
use a PHP globals like $_COOKIE[] or $_SESSION{]; To store the id of that user
or you can use a database field of array type.It will store the value of button clicked by a particular user(using a database will more efficient because you can use it any time and it do not expires )
Related
I have a web page that loads all the data from a mysql database called datalist.php
From this page I can edit record by record with a button that redirects you to an editdata.php page adapted to the fid of the record.
Once edited as they want to see the changes, I don't redirect them to the main one letting them see the changes and simply clicking back or with a button they return to the datalist.php without any problem.
The button is this
echo "<p id='parrafo'><a style='padding:1px 20px'class='button rounded-0 primary-bg text-white w-0 btn_1 boxed-btn' href='javascript:history.back() '><--</a></p>";
PROBLEM
I added a search engine where the displayed data can be filtered.
When they use the search engine from datalist.php, I direct them to a page called search engine.php where, through a post method, I store what they are looking for in a variable and the data that users want appears.
But when they edit a filtered record, it is edited without problems, but when they go back, they return to the search engine.php and the message appears:
"Confirm form resubmission In order to display correctly, this web page needs the data you entered earlier. You can submit that data again, but that will cause the page to repeat all previous actions. Press Reload to submit the data and display the page.
Hit the page refresh button to resubmit the data needed to load the page."
Of course, if they update, they come back when the filtered data comes out.
Isn't there any way to store the variable used in the search so that when I go back I don't get this error or any solution??
simple! when user will submit form for that variable instead of making post request
option1: just use get request __url__?variable=... but this will not remember the variable when you go back
option2: store the variable in the cookie and just go to next page (eg. window.location.href = '...';). and in next page access the cookie from php.
If you are wanting to show the form to the user as a confirmation, but without the possibility of another post, then remove the form element and the button. Display all other boxes as they are (with the values populated from the POST array).
And display another message telling them that it has been successful.
You are using PHP, you can achieve this easily with it. If you are unsure, then post a short version of your code in a separate question.
I have an app that has to send bulk email to selected users. I need to display my users table with a checkbox per row and a submit button with a form handler to operate on checked rows. Considering the built-in features of GC like the filter and column sorting, pagination, etc... I thought using GC would be a good solution. I found info on adding the checkbox. How do I add a submit button and form handler? Anyone have a hint or two where to start?
There are several ways to do this. I will explain two ways here.
Create the checkbox, for the id value use some unique data of the user details such as userid or username. After that on change of check box selection call a javascript method to update the hidden field with the current status. You can use some special delimiter to separate the check boxes. Let say if check box with id 1,5,6 are checked then the hidden field should be updated to "1#5#6". In the server side you can use the explode method to make an array and then you will have the usernames in array.
Another way is using AJAX and processing it immediately. I have used this way on my Codeigniter Code Generator at http://www.thephpcode.com to update the user roles' permissions. An admin user can grant or revoke permissions to a user role. All the permissions will be displayed with check box and with current status. When changed it will be updated immediatly through AJAX call.
I am using a Joomla form add-on.
the form already captures logged-in user-name on submit.
Now I want to create two fields
verified- a button field, which allows me to add javascript code for the button.
Verified by - (it can be a calc field type, where I can use both Javascript and PHP)
Every time the button verified is clicked, the verified by field captures the logged in user's name, if the button is clicked second time by another user, it adds the name of that second user in the verified by field, not overwrite it.
Your question isn't very clear, but from the sound of the question's title you might want to check out MySQL triggers.
I have a form with many inputs, but not all inputs must be filled in.
Form action is set to a php file, which checks which inputs are set and builds a query to query MySQL.
Then I display the results on the main page, and the users may click on an ad to show.
When clicked an ad, a new page opens with several options for the user (change ad, delete ad, save ad etc).
On this page, I am currently struggling with a 'back to search results' button/link. I don't know how to do this. I thought firstly about the 'history.go' to just make a 'back' button, but if the users would use one of the options on the page then the 'back' wouldn't work!
Another way would be to somehow save the query in a hidden input and pass it to the 'show ad' page or something... But this seems unsafe as the query is visible to users!
Do you have any ideas or suggestions?
Thanks
Save the data you need to build the query in the page. This could be a copy of the original form with all the input types converted to hidden.
I want to make the application like below.
First there is a page with four radio buttons. The user clicks on any of the radio buttons but doesn't save and he goes to another page. Then if he comes back to same page with the radio buttons it shows the selected radio button before he goes to another page.
How can I do it by using jQuery and PHP?
You can either save the value in a database, or in a cookie (with javascript, jquery: settings cookie with jquery
EDIT: As palasso said, you can also use php sessions instead of the cookie, all depends on your need.
For example, the user can change the cookies you created (they are just .txt files) and alter the information within.
In your situation, this dont seem to be a problem (becose the cookie depends on the checkboxes the user clicked).
So, you should go with database storage if:
Need to store the checks for long time;
Need to do complex elaboration on them;
Else, go with cookies/session.
First of all you have to start session in your php script. Then use ajax request on a radio button click storing the selected value in the session.
Sessions and cookies are the easier options. I prefer sessions.
Add a click event to the radio button
When clicked save the selected option into a php session
Each time the page is loaded check if the selected value exists in your session and load it.