PHP脚本未加载托管在xampp中的[重复]

Posted

技术标签:

【中文标题】PHP脚本未加载托管在xampp中的[重复]【英文标题】:PHP script not loading that hosted in xampp [duplicate] 【发布时间】:2019-01-24 20:20:32 【问题描述】:

我在 xampp 中有一个小型网站主机。我正在为此使用最新版本的 xampp。但是当我在网络浏览器上输入 URL 时,该 php 页面根本没有加载。其他页面正在加载没有任何问题。这是完整的代码:

<!DOCTYPE html>
<!--
    Industrious by TEMPLATED
    templated.co @templatedco
    Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
-->
<html>

<head>
    <title>ARTIK Cloud based Smart Parking System</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link rel="stylesheet" href="assets/css/main.css" />

    <style>
        rainbowParking 
            display: block;
            background-color: #dddddd;
            padding: 30px;
            font-size: 70px;
            line-height: 60%;
            margin-left: 40px;
            margin-right: 40px;
            border-style: groove;
        

        indigoParking 
            display: block;
            background-color: #dddddd;
            padding: 30px;
            font-size: 70px;
            line-height: 60%;
            margin-left: 40px;
            margin-right: 40px;
            border-style: groove;
        

        div.container 
            margin: 15px;
        

        div.left,
        div.right 
            float: left;
            padding: 10px;
        

        div.left 
            background-color: white;
            width: 900px;
            height: 500px;
        

        div.right 
            background-color: #dddddd;
            width: 360px;
            height: 400px;
            margin-top: 20px;
            margin-bottom: 100px;
        

        div.right-output 
            background-color: #dddddd;
            width: 360px;
            height: 400px;
            overflow-y: auto;
            margin-top: 20px;
            margin-bottom: 100px;
        

        .myBox 
  position:absolute;
  left:471px;
  top:94px;
  width:204px;
  height:183px;
  filter:alpha(opacity=90);
  opacity:0.90;
  z-index:7;


.redBox 
  background: red;


.greenBox 
  background: green;



.square-box 
    position: relative;
    width: 20%;
    overflow: hidden;
    background: blue;

    &:before 
        content: "";
        display: block;
        padding-top: 100%;
    


.square-content 
    position:  absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    color: white;

    div 
       display: table;
       width: 100%;
       height: 100%;
    

    span 
        display: table-cell;
        text-align: center;
        vertical-align: middle;
        color: white
    



    </style>
</head>

<body class="is-preload" >

    <!-- Header -->
    <header id="header">
        <a class="logo" href="index.html">SmartPark</a>
        <nav>
            <a href="#menu">Menu</a>
        </nav>
    </header>

    <!-- Nav -->
    <nav id="menu">
        <ul class="links">
            <li>
                <a href="index.html">Home</a>
            </li>
            <li>
                <a href="websocket.html">Parking Lot Status</a>
            </li>
            <li>
                <a href="generic.html">Parking Space Availability</a>
            </li>
        </ul>
    </nav>

    <!-- Heading -->
    <div id="heading">
        <h1>ARTIK Cloud based Smart Parking System</h1>
    </div>

    <!-- Main -->
    <section id="main" class="wrapper">

        <h2 style="color:green;text-align:center;font-size: 50px">Main Parking Status</h2>

        <div class="container">


<?php
$user = 'root';
$password = '';
$db = 'smart_parking';
$host = 'localhost';
$port = 1234;

$link = mysqli_init();
$success = mysqli_real_connect(
   $link,
   $host,
   $user,
   $password,
   $db,
   $port
);


//List the Columns for the Report 
echo "<table border='1'> 
<tr> 
<th>Sensor ID</th> 
<th>Slot Status</th> 
</tr>"; 

$result = mysql_query($success,"SELECT sensorId,slotStatus,time FROM arduino_ultrasonic au1 WHERE timestamp = (SELECT MAX(timestamp) FROM arduino_ultrasonic au2 WHERE au1.sensorId = au2.sensorId)");
while($row = mysql_fetch_array($result)) 
   
  echo "<tr>"; 
  echo "<td>" . $row['sensorId'] . "</td>"; 
  echo "<td>" . $row['slotStatus'] . "</td>"; 
  if($row['sensorId']=='Ultra_sensor_01' && $row['slotStatus']=='Occupied') // [val1] can be 'approved'
         echo "<td style='background-color: #FF0000;'>".$row['slotStatus']."</td>"; 
  else if($row['sensorId']=='Ultra_sensor_01' && $row['slotStatus']=='Free')// [val2]can be 'rejected'
         echo "<td style='background-color: #008000;'>".$row['slotStatus']."</td>"; 
  else if($row['sensorId']=='Ultra_sensor_02' && $row['slotStatus']=='Occupied')// [val2]can be 'rejected'
         echo "<td style='background-color: #FF0000;'>".$row['slotStatus']."</td>"; 
  else if($row['sensorId']=='Ultra_sensor_02' && $row['slotStatus']=='Free')// [val2]can be 'rejected'
         echo "<td style='background-color: #008000;'>".$row['slotStatus']."</td>"; 
  else if($row['sensorId']=='Ultra_sensor_03' && $row['slotStatus']=='Occupied')// [val2]can be 'rejected'
         echo "<td style='background-color: #FF0000;'>".$row['slotStatus']."</td>"; 
  else if($row['sensorId']=='Ultra_sensor_03' && $row['slotStatus']=='Free')// [val2]can be 'rejected'
         echo "<td style='background-color: #008000;'>".$row['slotStatus']."</td>";  
  echo "</tr>"; 
   
echo "</table>";  
$mysqli->close();
?>

            </div>


    </section>

    <!-- Footer -->
    <footer id="footer">
        <div class="inner">
            <div class="content">
                <section>
                    <h3>SHU Final Year Project</h3>
                    <p>This project is based on the IoT concept. I used Raspberry Pi, Arduino and Samsung Artik cloud service to create this project.
                        This a simple demonstrantion of upcoming smart parking.
                    </p>
                </section>
                <section>
                    <h4>Links</h4>
                    <ul class="alt">
                        <li>
                            <a href="https://raspberrypi.org">Raspberry Pi</a>
                        </li>
                        <li>
                            <a href="https://arduino.cc">Arduino</a>
                        </li>
                        <li>
                            <a href="https://www.artik.io/">Samsung Artik</a>
                        </li>

                    </ul>
                </section>
                <section>
                    <h4>Social Media Links</h4>
                    <ul class="plain">
                        <li>
                            <a href="www.twitter.com">
                                <i class="icon fa-twitter">&nbsp;</i>Twitter</a>
                        </li>
                        <li>
                            <a href="www.facebook.com">
                                <i class="icon fa-facebook">&nbsp;</i>Facebook</a>
                        </li>
                        <li>
                            <a href="www.instagram.com">
                                <i class="icon fa-instagram">&nbsp;</i>Instagram</a>
                        </li>
                        <li>
                            <a href="www.github.com">
                                <i class="icon fa-github">&nbsp;</i>Github</a>
                        </li>
                    </ul>
                </section>
            </div>
            <div class="copyright">
                &copy; CheshanJ. Photos:
                <a href="https://unsplash.co">Unsplash</a>, Video:
                <a href="https://coverr.co">Coverr</a>.
            </div>
        </div>
    </footer>

    <!-- Scripts -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/browser.min.js"></script>
    <script src="assets/js/breakpoints.min.js"></script>
    <script src="assets/js/util.js"></script>
    <script src="assets/js/main.js"></script>

</body>

</html>

我在 SQL 部分使用了 mysqli。如果您想知道 SQL 查询,那就是选择最新记录。 任何人都可以就此提出建议吗?如果有请分享。提前谢谢。

P.S:也出现这个错误:

Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\smartParking\slotstatus.php:192 Stack trace: #0 main thrown in C:\xampp\htdocs\smartParking\slotstatus.php on line 192

【问题讨论】:

mysql_query 在 PHP 5 中已弃用,在 PHP 7 中已完全删除。请改用 PDO 或 mysqli。 【参考方案1】:

您正在运行哪个版本的 PHP ? mysql已经贬值了。

在您的代码中从 mysql 更改为 mysqli

你的代码似乎还有mysql,检查!

    $result = mysql_query($success,"SELECT sensorId,slotStatus,time FROM arduino_ultrasonic au1 WHERE timestamp = (SELECT MAX(timestamp) FROM arduino_ultrasonic au2 WHERE au1.sensorId = au2.sensorId)");
while($row = mysql_fetch_array($result)) 

【讨论】:

我使用的是 PHP 7.2.6。所以我想我必须听从你的建议。谢谢。【参考方案2】:

使用 mysqli_query() 和 mysqli_fetch_array(),新版本的 PHP 不支持 'mysql' 函数。

【讨论】:

【参考方案3】:

错误消息表明您正在使用mysql_query 进行调用 mysql_query 自 PHP 5.5 起已被弃用。而是尝试;

$mysqli = new mysqli("example.com", "user", "password", "database");
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc();
echo htmlentities($row['_message']);

【讨论】:

我尝试了解决方案。然后出现错误:Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\smartParking\slotstatus.php:208 Stack trace: #0 main thrown in C:\xampp\htdocs\smartParking\slotstatus.php on line 208

以上是关于PHP脚本未加载托管在xampp中的[重复]的主要内容,如果未能解决你的问题,请参考以下文章

php文件中的xampp脚本不会延续到html文件[重复]

XAMPP:mySQL 未连接 [重复]

基本的 PHP 程序未在 XAMPP 中运行

php不会使用xampp运行[重复]

注意:未定义索引:[重复]中的图像

xampp 未显示保存在 htdocs 文件夹中的 .php 文件