Is there any way to get a data from a div, section or even an alert to database by using php ?
for example, my browser alerts a value or there's a div contains a value and I want to get that value into my database table. Is there any way ?

- 11
- 4
-
Sorry, it is unclear what the question is. It might make sense that you look at a few examples of how to process html forms and maybe some examples about ajax. – arkascha Apr 06 '14 at 19:17
2 Answers
You'll need to user Javascript AJAX to send that information asynchronous to the server.
For example, set a javascript handle that every time a div is clicked, An ajax call is sent to the server with the div's HTML value. Serverside you can now use the global $_POST variables to insert it to the database(or anything else you might want to do) - remember to sanitize your data ofcourse.
Some more information : How to make an AJAX call without jQuery?
First of all: PHP runs on the server, not in your browser, so the concept of a <div>
containing something is inexistant as far as PHP is concerned.
What you can do, and what would be the canonical way to do it, would be to use a client-side environment, such as JavaScript, to extract the value needed, then use e.g. an AJAX call to communicate this to the server running PHP, which would store it in the database.
Ofcourse having JavaScript from one source deal with the DOM from another source is a quite dangerous thing to do, so the browsers will do their uttermost to prevent it. This means, that if you want to extract data from a source you do not control, you might need to access it via a server-side loader, that injects the Java Script.

- 64,175
- 10
- 70
- 92