duanfoumi5620 2014-06-06 04:12
浏览 62
已采纳

使用PHP的HTML表单行为

I ran into an interesting wall today working on a simple form with PHP and HTML and can't think of a quick fix.

I'm using the PHP script I've written when the user presses submit on my HTML page. In order to re-display the page after running the script I simply write

include "html_forms.html" 

at the bottom of the PHP script. Firstly, this seems like a bad design for presenting the page as it needs to be constantly fully re-displayed but I couldn't figure out how to circumvent this problem.

The problem I'm more concerned with here though is that I'm trying to keep the form data from before the user first pressed submit by using PHP. To do this I modify the value of each input like this (within the HTML):

value = "<?php echo $website; ?>

However, when the webpage is first loaded from the HTML (I'm guessing it can't find the PHP to reference since the Submit button hasn't been clicked yet so) in my entry box on the page the first time it's loaded it prints <?php echo $website; ?>. If I load the PHP first it doesn't have that problem but this schism makes me question the overall design that I'm going for and although it might fix the problem in this case it seems like it only works because the simplicity of the webpage.

My main question is how to fix this? I've thought of looking into just emptying the html entries on the first go and other techniques but I'm not sure if this would be the best approach since making special cases especially for the first time the page is clicked seems like bad form.

Thanks in advance for the help guys and this is the first question I've asked on stack-overflow so let me know if there's anyway I could improve my question-asking and don't be too harsh on me!

  • 写回答

2条回答 默认 最新

  • doulu4203 2014-06-06 04:31
    关注

    Basically the issue is that your web server does not parse .html files by PHP interpreter. You have two options from here:

    1. If you use Apache you may configure .htaccess to have following line:

      AddHandler php5-script .html

    2. You may rename your .html file into .php file

    However both options are bad design: you should allow user to interact with your PHP script only and use underlying html as template if needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算