dpkrbe395930 2016-04-11 15:49
浏览 36
已采纳

在不使用输入标记的情况下在HTML中调用PHP文件

Is there any way to call a PHP file inside an HTML document without using an input tag?

I am trying to display some results of my database (as a table) using the form tag (file2.php) but I realize that the only way to display the results, is to have an input tag inside the form tag. Is there any way to simply display the results in my HTML website without using inputs?

Code:

<html>
<body> 
 <img src="file1.php"> 
 <form action="file2.php" method="post">
  <input type="submit" value="submit"> 
 </form>
</body>
<html>

My file2.php is
---
<?php
define('DB_NAME', 'name');
define('DB_USER', 'yyyy');
define('DB_PASSWORD', 'xxxx');
define('DB_HOST', 'localhost');

$link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if(!$link){
    die('Could not connect:' .mysql_error());
}

$db_selected = mysql_select_db(DB_NAME,$link);

if(!$db_selected){
    die('Can\'t use' .DB_NAME .':' . mysql_error()); 
}

 $cid=$_COOKIE["cid"];
 $sql= "SELECT * FROM table WHERE PID='$cid' ORDER BY SUBTIME ASC;";
 $result = mysql_query($sql);

 echo "<table border=1>
  <tr>
  <th> SUBMISSION DATE/TIME </th>
  <th> SYS </th>
  <th> DIA </th>
  <th> PULSE </th>
  <th> WEIGHT </th>
  </tr>";

  while ($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td align='center'>" . $row['SUBTIME'] . "</td>";
    echo "<td align='center'>" . $row['SYS'] . "</td>";
    echo "<td align='center'>" . $row['DIA'] . "</td>";
    echo "<td align='center'>" . $row['PULSE'] . "</td>";
    echo "<td align='center'>" . $row['WEIGHT'] . "</td>";
    echo "</tr>";
  }

  if(!mysql_query($sql)){
    die('Error:' .mysql_error());
  }

mysql_close();
?>
  • 写回答

1条回答 默认 最新

  • dongqian5639 2016-04-11 16:05
    关注

    You can't include a PHP file in an HTML file. You need to change the extension of the HTML to PHP and use include().

    <?php 
        include 'form2.php';
    ?>
    

    That is the easiest way to do it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解