我创建了一个存储有关船只信息的数据库,当我尝试在PHP中使用这些数据时,我在数据库中添加了一些新字段,但是当我在PHP中使用它们时,它们会返回“Undefined index:fieldName”
据我所知,这意味着索引尚未设置,所以我检查了数组的内容,发现除了新的字段外,所有字段都在那里,但是我可以在phpmyadmin中查看它们。 / p>
PHPMyAdmin中: 请参见图片:https://dl.dropboxusercontent.com/u/65222600/phpmyadminshot.png
PHP代码:
<?php
include_once "php/connect.php";
$result = mysqli_query($con,"SELECT * FROM vessels");
while($row = mysqli_fetch_array($result)){
print_r( $row );
}
?>
PHP返回:
Array (
[0] => 1 [idVessels] => 1
[1] => 1 [userId] => 1
[2] => cams boat [name] => cams boat
[3] => 1000000000 [price] => 1000000000
[4] => 0 [VAT] => 0
[5] => GBP [Currency] => GBP
[6] => UK [Location] => UK
[7] => ME [builder] => ME
[8] => ME [make] => ME
[9] => ME [model] => ME
[10] => 10/10/13 [yearConstructed] => 10/10/13
[11] => 1 [cabins] => 1
[12] => 1 [heads] => 1
[13] => 1 [#engines] => 1
[14] => ME [engineModel] => ME
[15] => 100 [enginePower] => 100
[16] => petrol [fuelType] => petrol
[17] => 122 [nominalLength] => 122
[18] => 122 [overallLength] => 122
[19] => 122 [waterlineLength] => 122
[20] => 122 [beam] => 122
[21] => 122 [maxDraft] => 122
[22] => leather [hullMaterial] => leather
[23] => MINT [hullType] => MINT
[24] => MINT [keeltype] => MINT
[25] => 122 [displacement] => 122
[26] => 122 [waterCapacity] => 122
[27] => 2014-01-10 02:18:39 [dateAdded] => 2014-01-10 02:18:39
[28] => For Sale [status] => For Sale )
并且无处是描述或primaryImageURL。
非常感谢任何帮助,谢谢
答案 0 :(得分:1)
感谢所有帮助人员,结果我使用的是项目数据库而不是我的Dev DB
答案 1 :(得分:0)
尝试明确引用字段名称:
$result = mysqli_query($con,"SELECT IdVessels, userId, name, description, primaryImageURL FROM vessels");
这样你就能更快地找到问题。如果db回答字段未存在,则可能是您将连接指向旧数据库。