sdn30studio3 Posted August 30, 2021 Share Posted August 30, 2021 I've just started learning php today, but after installing XAMPP i wrote my first code but it came out only as text in the browser, i have tried all i know to resolve it no solution. Please i need help, kindly guide me. <!DOCTYPE html> <html> <head> <title>Gathering Information</title> </head> <body> <?php $studentName = $_POST['studentName']; $grade = $_POST['grade']; $section = $_POST['section']; $classTeacher = $_POST['ClassTeacher']; echo '<p>Student Informtation</p>'; echo 'Student Name is ' . $studentName; echo 'He/She is in this grade: ' . $grade; echo 'he is also in this section: ' . $studentName; echo 'Is being taught by: ' . $classTeacher; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/313622-xampp-indexphp-displaying-as-text-in-browser/ Share on other sites More sharing options...
Barand Posted August 30, 2021 Share Posted August 30, 2021 1) Don't post your problems on the Introductions page 2) Use <> button in toolbar when posting code 3) Format your code. Before you process POST data, you need to check that data has been posted to the page and only process if it has. To check... if ($_SERVER['REQUEST_METHOD']=='POST') { // process data } Does the filename that contains that code end with .html or .php ? Quote Link to comment https://forums.phpfreaks.com/topic/313622-xampp-indexphp-displaying-as-text-in-browser/#findComment-1589459 Share on other sites More sharing options...
ginerjm Posted August 30, 2021 Share Posted August 30, 2021 And learn to write your code in separate lines - makes it far, far easier to read, interpret and to maintain. Another good plan would be to execute your php code FIRST and then to output the html code with the dynamic parts coming in the form of php vars that you build from that php logic you executed earlier in the script. <?PHP do php stuff like grabbing the posted data. format some results into php vars Now start echo-ing html code and inserting those php vars where you want the generated php results to show up. then exit php. Read up on using the heredocs construct. Makes outputting html and php vars much much easier IMHO Quote Link to comment https://forums.phpfreaks.com/topic/313622-xampp-indexphp-displaying-as-text-in-browser/#findComment-1589462 Share on other sites More sharing options...
benanamen Posted August 30, 2021 Share Posted August 30, 2021 Additionally, you need to access the file through a server, not the filesystem. If your URL starts like file:/// you are not using a server. Quote Link to comment https://forums.phpfreaks.com/topic/313622-xampp-indexphp-displaying-as-text-in-browser/#findComment-1589465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.