External PHP execution problem- read description | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

External PHP execution problem- read description

Hi. So I have an external PHP file and want it to be executed using <form> in html The basic project is to fill the form and of course, on submit, a PHP file is executed. The PHP file is referenced elsewhere in the HTML. heres the link for an example: https://code.sololearn.com/W5l83JmFIcWM/#html Okay so the PHP displays the content of the input text element and places it elsewhere in the body. As you can see, I placed the php file include code in the area that i want the php to be placed (using echo, although i am open to other methods). I would rather have the PHP be in an external file. Is there some way in PHP to append elements? Im REALLY bad at PHP so PLEASE give me a suggestion. I would rather you list methods or factors that would help with this task rather than posting a piece of code that does it all for me. Thanks!

11th May 2018, 1:47 AM
privrax.
privrax. - avatar
4 Answers
+ 1
php doesn't work like that. 1st, php includes on a page are parsed into html etc before the page is sent to the browser (php lives only on the server) then the browser gets just the html css and js and renders it. so you can't send it to an include on the page as that php doesn't exist any more having turned itself into web languages. What you need is one of two things. 1. a database to hold the messages and a php file on the server to put and get data from the database. on the front end you need javascript using ajax ti send and get data from the server php file. 2. you can use the web worker javascript api to set up a dedicated thread that just listens to another js file that queries the server php for changes on when one comes in updates the front end. either way you need php on the server to deal with the database or other storage medium for the messages. and you need js fromt end to pass data between front and back.
11th May 2018, 2:37 AM
Adam
Adam - avatar
+ 1
Alright thanks buddy.
11th May 2018, 3:07 AM
privrax.
privrax. - avatar
0
What you need is Javascript. php runs on the server. It is for interacting with a database or for pulling data from the database and building html dynamically. Javascript runs in the browser and can read the value from inputs and put them elsewhere on the page.
11th May 2018, 1:53 AM
Adam
Adam - avatar
0
@adam Alright. I have considered this. However, what I am actually developing is an IRC chat. When the user inputs the text message and clicks "send' (which is all in a form element), a piece of PHP gets the user's name from a text file, and displays it before the content of the message, as so: USER: message content. Is there any way that I could somehow grab the user's name from the PHP file (which returns it after grabbing it from the text file) with JavaScript? Because right now my plan is to directly post the user's name with PHP. And, I need the message to go up to the PHP file which then drops it off in a text file to be read by the other client. Any ideas?
11th May 2018, 2:01 AM
privrax.
privrax. - avatar