我正在使用Mamp中的php和数据库制作基于文本的冒险游戏。
我已将房间描述放入一个表格,每个房间都有一个身份证号码。但是,我无法从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
?>