<;b>;通知</b>;:未定义变量:PHP用于根据mySQL中的路径显示来自服务器的图像
正在尝试使用PHP将图像上载到服务器和路径mySQL。然后,另一个PHP文件显示该图像。但是,我在以下行中收到“注意:未定义变量”错误,并且图像显示为一个断开的图像:<;b>;通知</b>;:未定义变量:PHP用于根据mySQL中的路径显示来自服务器的图像,php,html,mysql,Php,Html,Mysql,正在尝试使用PHP将图像上载到服务器和路径mySQL。然后,另一个PHP文件显示该图像。但是,我在以下行中收到“注意:未定义变量”错误,并且图像显示为一个断开的图像: <img src="<?php echo $row[" ImagesPath"]; ?>" /> 这是显示图像的代码 <!--?php include("mysqlconnect.php"); $select_query = "SELECT `ImagesPath` FROM `offers
<img src="<?php echo $row[" ImagesPath"]; ?>" />
这是显示图像的代码
<!--?php
include("mysqlconnect.php");
$select_query = "SELECT `ImagesPath` FROM `offerstbl` ORDER by `ImagesId` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?-->
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<img src="<?php echo $row[" ImagesPath"]; ?>" />
</td>
</tr>
</tbody></table>
<!--?php
}
?-->
" />
正如错误所说,$row未定义
您的查询执行行未包含在php代码中。您使用en-HTML注释对这些行进行了注释(并且删除了php开头标记)。我还删除了“ImagesPath”之前的空格
固定代码:
<?php
include("mysqlconnect.php");
$select_query = "SELECT `ImagesPath` FROM `offerstbl` ORDER by `ImagesId` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<img src="<?php echo $row["ImagesPath"]; ?>" />
</td>
</tr>
</tbody></table>
<?php
}
?>
" />
您在“/>
在第一个引号和ImagesPath之间。空格不会影响错误,很遗憾,谢谢你。你真的不知道这里有什么问题吗?你知道注释代码会改变它的工作方式吗?看看下面凯文的答案。一次只显示一张图片,而不是所有图片一起显示,这可能吗。也许可以使用一些onclick类型的函数来切换到下一个图像?当然,这不是这个问题的目标。
<!--?php
include("mysqlconnect.php");
$select_query = "SELECT `ImagesPath` FROM `offerstbl` ORDER by `ImagesId` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?-->
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<img src="<?php echo $row[" ImagesPath"]; ?>" />
</td>
</tr>
</tbody></table>
<!--?php
}
?-->
<?php
include("mysqlconnect.php");
$select_query = "SELECT `ImagesPath` FROM `offerstbl` ORDER by `ImagesId` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<img src="<?php echo $row["ImagesPath"]; ?>" />
</td>
</tr>
</tbody></table>
<?php
}
?>