php - 从 html 执行查询?

标签 php html mysql

我想从我的表格中选择包含 2 列的内容:Judul, Isi.

<head><link type="text/css" rel="stylesheet" href="addnewpage.css"/</head>
<body>

<?php
$k = mysqli_connect("localhost", "root", "", "ubm_2015");
$sql = "select * from proses;";
$h = mysqli_query($k, $sql);
$b = mysqli_fetch_array($h);
?>

<div id="box">
    <div id="left">
        <div id="logo">
            <img src="gambar/arg.gif" height="50" width="200"/>
        </div>
        <div id="menu">
            <div class="current">Pages</div>
            <a href="contact.html"><div class="menu">Contact</div></a>
            <a href="user.html"><div class="menu">User</div></a>
        </div>
    </div>
    <div id="right">
        <div id="top">
            Welcome, admin
            <a href="login.html"><input type="submit" value="log out" /></a>
        </div>
        <div id="head"><h1>Edit Pages</h1></div>
        <div id="form">
            <table>
                <tr>
                    <td><label>Judul : </label></td>
                    <td><input  type="text" name="judul" value="<?php echo $b['Judul']; ?>" /></td>
                </tr>
                <tr>
                    <td><label>Body : </label></td>
                    <td><input  type="text" name="isi" value="<?php echo $b['Isi']; ?> "/></td>
                </tr>
                <tr>
                    <td><label>Bahasa : </label></td>
                    <td>
                        <select>
                            <option value="ind">Indonesia</option>
                            <option value="eng">English</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><label>Parent : </label></td>
                    <td>
                        <select>
                            <option value="p">Parent</option>
                            <option value="sm">Sub-Menu</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
        <div id="button">
            <input type="button" value="Send"/>
            <a href="page.html"><input type="button" value="Back"/></a>
        </div>
    </div>
</body>

但是输入框显示<?php echo $b['Isi']; ?>而不是表格的内容。

注意:

  1. I saved the html code in htdocs folder, which inside the xampp folder.

  2. The format is html.

  3. Database name : ubm_2015

请帮忙。非常感谢。

最佳答案

我假设您正在通过网络服务器访问此文件(不是 file://,而是 http://)。您的网络服务器必须将您的代码作为 PHP 代码处理,而不是 HTML 代码。尝试使用 .php 扩展名。

在您的网络服务器配置中,您将有类似的内容:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
  SetHandler application/x-httpd-php
</FilesMatch>

因此 .php(和类似)文件将作为 PHP 代码进行处理。

关于php - 从 html 执行查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34132266/

相关文章:

php - Joomla 错误信息文件目录

php - 如何检测php文件所在的目录

javascript - 用 Javascript 突出显示单词,我错过了什么?

JQUERY UI - 边界半径问题。 IE7和IE8不支持,需要圆 Angular 的方法

php - Joomla 中的 mysql 下一个和 orderby 中的上一个 SQL 语句

php - 是否有任何PHP框架可以集成到现有项目中?

javascript - 以编程方式提交表单时防止重定向

html - 拉伸(stretch)背景超出 parent 宽度html css

mysql - 与相关产品表中相同型号的产品

php - 正确显示关联数组的结果 Laravel/PHP