【发布时间】:2018-10-20 14:45:53
【问题描述】:
我正在使用 Mamp 中的 php 和数据库制作基于文本的冒险游戏。
我已将房间描述放入一个表格中,每个房间都有一个 ID 号。但是,我无法从 sql 中获取表,我总是收到 HTTP ERROR 500。
如果我取出 $sql - ?>,我知道数据库会在页面加载时连接。
php 代码如下:
<?php
// Extract the page data from the d/b
// define the constants
// note best practice is to keep these separate so values can be
changed easily
$servername = "localhost";
$username = "root";
$password = "1234";
$dbname = "Room";
// Create connection using the above values
$conn = mysqli_connect($servername, $username, $password, $dbname);
// extract values from d/b
$sql = 'SELECT * FROM Room, Rooms'; // build the query string
$result = $conn->query($sql); // execute the query - sends back a
list of records
$row = $result->fetch_assoc(); // select the first row/record
$description = $row['RoomDesc']; // select the description of the
room
?>
【问题讨论】:
-
'changed easy' 是上一个注释的一部分
-
有几个 cmets 已经断线,也许编辑问题以将它们放在一条线上?另外 - 我已经添加了一个答案,如果这有帮助,请告诉我:)
-
如果您找到了问题的答案,请将其标记为“已接受”
-
你有一个错字。如果您在 db Room 内有一个表 Rooms,则它是 Room.Rooms。无论如何房间,房间是无效的mysql