I’m no PHP expert, and it’s a bit out of the scope of this forum, but - aren’t you combining front-end and backend in a way that will prevent it from actually working?
The basic idea behind AJAX is that the front-end is sending a request to the server (not an sql query), and the server gets this request and does whatever it wants with it (like an sql query). So when pressing the button, you need to use JavaScript (and probably not php) to get the value and send it to the server.
The code you wrote is not dynamic. It’s fixed to the point of writing the document, which means that unless there is already content in text.text, p1 will always be empty.
PHP is precompiled, script elements are post compilation.
You would have to do what @RaananW and look into ajax. Where as you would have a secondary PHP file that you POST or GET with the xhr() and then pass the data package to it from that.
you can then have a response from the php page that you did the request to letting you know if the insert was successful or not and then have your javascript do the correct callbacks.
Order is:
User-Page Loads
Script requests XHR with Data package
Server Responds Compiles and runs the PHP script you requested.
XHR request responds with the results depending on your PHP scripts output
You parse the response and go about your day.