我如何启动PHP程序? [英] How do I start PHP program?

查看:74
本文介绍了我如何启动PHP程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在写一个查询的MySQL数据库的网站,只是以表格形式返回它的内容。这是我第一次使用PHP(我已经阅读过教程,但找不到解释这一部分的教程),并且当我启动使用php的查询时,它只是打开另一个仅显示php代码的浏览器窗口。不知道为什么它这样做,所以也许你们可以帮助。



这是我的HTML:

 <!DOCTYPE html> 
< html>
< head>
< meta charset =UTF-8>
< title>插入网址< / title>
< style type =text / css>
label {width:5em;向左飘浮; }
< / style>
< / head>
< body>
< form method =postaction =db_query.php>
< div>< label>网址:< / label>
< input type =textname =URL>< br>< / div>
< div>< label>说明:< / label>
< p>< input type =submitvalue =Query>< / p>
< / form>
< / body>



这里是PHP:

 < html> 
< head>
< meta charset =utf-8>
< title>搜寻结果< / title>
< style type =text / css>
body {font-family:sans-serif;
background-color:lightyellow; }
table {background-color:lightblue;
border-collapse:collapse;
border:1px纯灰色; }
td {padding:5px; }
tr:nth-​​child(奇数){
background-color:white; }
< / style>
< / head>
< body>
<?php

$ db_connect = mysql_connect(192.168.0.1,db,password);
$ db_query =SELECT * FROM urltable;

if(!$ db_connect)
{
die(无法连接到数据库);
}
else
{
print(Connected to the Database!);
}

?><! - 结束PHP脚本 - >

< table>
< caption>SELECT<?php print($ db_query)?>
FROM URLS< / caption>
<?php
//获取结果集中的每条记录
while($ row = mysql_fetch_row($ result))
{
//构建要显示的表结果
print(< tr>);
$ b foreach($ row为$ value)
print(< td> $ value< / td>);

print(< / tr>);
} // end while
?><! - end PHP script - >
< / table>




忽略HTML代码中的两个输入框,它们只是现在的占位符。无论如何,当我点击查询按钮,它只是打开一个新的浏览器,显示php代码,而不是实际的查询。我不确定我在做什么错误?

解决方案

要执行PHP,您需要需要一个像Apache这样的web服务器,可以处理你的请求。



你可以看看 XAMPP (Windows,Mac和Linux), MAMP (仅适用于Mac)或 WAMP (仅限Windows)运行本地Web服务器。


So I'm writing a website that query's MySQL db and just returns what's in it in a table form. This being my first time using PHP (I have read tutorials but can't find one where it explains this part) and when i launch the query that uses php it just opens another browser window that shows the php code only. Not sure why its doing this, so thought maybe you guys can help.

Here is my HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert URL</title>
    <style type = "text/css">
        label { width: 5em; float: left; }
    </style>
</head>
<body>
    <form method = "post" action = "db_query.php">
        <div><label>URL: </label>
            <input type="text" name="URL"><br></div>
        <div><label>Description: </label>
            <input type="text" name="Description"></div>
        <p><input type = "submit" value = "Query"></p>
    </form>
</body>

Here is the PHP:

<html>
<head>
  <meta charset = "utf-8">
  <title>Search Results</title>
<style type = "text/css">
     body  { font-family: sans-serif;
             background-color: lightyellow; } 
     table { background-color: lightblue; 
             border-collapse: collapse; 
             border: 1px solid gray; }
     td    { padding: 5px; }
     tr:nth-child(odd) {
             background-color: white; }
  </style>
 </head>
 <body>
  <?php

        $db_connect = mysql_connect("192.168.0.1", "db", "password");
        $db_query = "SELECT * FROM urltable";

        if (!$db_connect)
        {
            die("Could not connect to database");
        }
        else
        {
            print("Connected to the Database!");
        }

     ?><!-- end PHP script -->

     <table>
     <caption>Results of "SELECT <?php print( "$db_query" ) ?> 
        FROM URLS"</caption>
     <?php
        // fetch each record in result set
        while ( $row = mysql_fetch_row( $result ) )
        {
           // build table to display results
           print( "<tr>" );

           foreach ( $row as $value ) 
              print( "<td>$value</td>" );

           print( "</tr>" );
        } // end while
     ?><!-- end PHP script -->
  </table>

Ignore the two input boxes in the HTML code, they are just place holder for now. Anyways when I hit the Query button it just opens a new browser that shows the php code and not the actual query. I'm not sure what I'm doing wrong??

解决方案

To execute PHP you are going to need a web server like Apache that will handle the requests for you.

You can take a look at XAMPP (Windows, Mac and Linux), MAMP (on Mac only) or WAMP (on Windows only) to run a local web server.

这篇关于我如何启动PHP程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆