dpkrbe395930 2016-04-11 07: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 08: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部