Initially, as can be seen in this unsuccessful attempt: Undefined index error when sending variable from jquery to php and this unsuccessful attempt:Passing Jquery variable to php within a modal
I was trying to pass a variable from php, to jquery and back to php.
Basically I am generating images form a database in a php loop. When the user selects an image, I want the id of that image to be passed to the modal so that I can query the database again (based on that id) and get more information.
Is there another way of doing this other than the methods outlined in the posts above. For some reason those do not return the result.
The difference between Send PHP variable value to JavaScript popup window in same page and my question is that I want it as a heading.. and as a variable so I can query the database again. I am not using this to input values into a form
Related
I need to get a text that the user has select with pointer and put it to some variable in PHP. So, the user should select some text in one div, then click submit button (in another div), and then I need to store that part of the text to some variable. Can anybody help me?
You would have to set an onclick listener (I prefer to use JQuery for this) so that when the user clicks the submit button, you grab the selected text from the div. You could probably do that in a way found here:
Get the Highlighted/Selected text
Since javascript and HTML are front-end and PHP is back-end, you cannot simply place the selected value into a PHP variable. Instead, you can use an ajax request to send the data to a PHP function. I'm not sure what you are doing with it after that, but sending an ajax request and including the selected text in the data section of the request, and then retrieving it in your PHP file/function and storing it in a variable there. This question should help in that regard: Passing Javascript variable to PHP using Ajax
I've managed to construct a webpage template that has all the elements for a home page but I want to use the data in my database to then submit to produce results coming out once submitted.
When I choose the menu (which has successfully come through from the database) when I click submit and have a second php page to make this submit work, I do not get any results from the database or at best showing what I have selected.
What code do I need to produce results on submit page that would hold all the data selected?
I really am a beginner at this and using PHP, HTML, and Dreamweaver as my builder.
At first you have to understand HTML form methods and how to access form data using PHP.
For getting the values of the select box you can go to this link.
Get select box value using $_POST
Hi all I am developing web app using php, jquery and bootstrap. Now in this app what i am doing is that i am getting a value from button on button click event and passing the value to the ajax, jquery and then jquery to the php file where it will be processed and this value is stored in an array. Every time new value comes value is passed through jquery and then to php where the value is pushed in array. Now let's assume that i have refreshed the page, will my array will be empty on page refresh or it will hold the value in that php file. The structure of files is like HTML/CSS file containing the form, jquery file containing all the jquery functions and php file processing the data. If html page gets refreshed will the array become empty or not ... ?
The php array will be empty and/or will only ever have one value in it.
This is because each request via ajax will be a new request, which is asynchronous, to the current request.
A solution would be to store the array in the PHP file in a session, and retrieve the array from the session.
That way the data will persist across multiple requests.
I have a form which has two input field called firstname and lastname with a submit button called
submit. The input fields use twitter's typeahead.js with custom event trigger (typeahead:selected)
Thus, when the firstname is selected from the dropdown, I have a ajax call in the trigger which post the
enrollment no of the selected person to another php page(xyz.php).
Here on xyz.php
If I store that enrollment number in a variable
$link = POST['number'];
Now this works just fine.
But the problem is when I click my button I have another AJAX call to the same php file.
And now I cannot use $link. It says Notice: Undefined index: number
Is there anyway I can get my variable to store the data permanently?
You can use session on the server side to store data across requests.
You can find more information here:
http://www.php.net/manual/en/intro.session.php
You can use sessions or a text file or a cookie, it depends your needs.
I have a problem posting from ajax elements.
I created a php page that reads some data from the database and renders a html page with a table inside. The user can modify the values in the table and submit the changes to the database.
Everything worked fine, but I needed to dynamically update the content of part of html table. So, I put a tbody element in the page and used a js function to load elements inside the tbody element. My js function uses a XMLHttpRequest object to call another php page. The second php page reads the database filtering the data by the input posted variables and creates a html table that is sent back to the first php page. It works perfectly, my html table is filled with data dynamically read from the database.
My problem is when I try to submit the data changed in the table: I can read with the _REQUEST all elements of the first php page but not the section created with ajax so I can't update my database. If I check the content posted to the second page, I can see that the table section is not posted at all. Also, in the first page I can read the elements ID and NAME of the table with a js script, so they are in the first page but they are not posted to the second page.
Do you have any suggestion?