简体   繁体   中英

Naming index page php or html when i have a php include

I have an index.html page that within it has an signup form. Now the page in itself does not have any php code, but it does have an include .php file that does contains the php code that appends the DB with a new user.

Now, i know that if i have to run some php code before the page is rendered i have to name it .php , but is that rule valid if i just call a php code from another page.

sry, i dont have the code at hand so here is a "concept code":

 <div class="conteiner"> <div class="row"> <form action="includes/signup.php" method="POST"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" id="exampleInputPassword1" placeholder="Password"> </div> <button type="submit" name="submit_reg " class="btn btn-primary">Submit</button> </form> </div> </div> 

The includes/signup.php just holdes some php code/html code that inserts data into DB. It also includes a check written in php that checks if the submit button has been clicked before executing the code, if it has not then returns the user to the index.html / .php (depending on what you tell me).

The reason im asking is, i have a problem with my code where (btw. the signup.php when executed returnes error handler if failed and ?=signup_succes if it ran correctly.) i execute the code and i get a returned succes but the dp has not been appended. But that is a problem for another post. So, im just checking does the naming of the index file play a role in it before i start changing index.html to index.php in every file i have it written in.

Sry if this has been asked before, i did some research but was unable to find a concrete answer.

yes, you only include php file in other php file, you can not run php functions in html file.

But you can post data from html file to php file and get data in json format.

Naming index page php or html when i have a php include --> .php extension

Thank you

By

but it does have an include .php file that does contains the php

Do you mean that your sign up form is referencing signup.php through the action attribute?

If you are linking to a url that uses php, no you do not need to save it with an extension of php because there's no server-side parsing needed to process non-existent php

Be careful to say "include" because there is PHP syntax to "include" a php file in php code, so that's confusing.

Side-note: It certainly does not hurt to make all your files .php to begin with though if you do end up needing to use it in the future, especially if you don't want to worry about adding 301 redirects for changed URLs (for SEO purposes).

Yes you can point an html form action inside an .html file to an .php file with no issues, this is perfectly fine.

However most php developers will rename all files within the project to .php instead of .html usually.

You can write html code inside a php file, just dont add the php opener at the start. like this example below.

<p>This is an example of html before php</p>
<?php echo 'this is an example of php'; ?>
<p>This is more html after php</p>

You can change index.html to index.php and keep the form code as it is. no need to add php if the index does not need php. however still rename it to index.php is the common solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM