当前位置: 首页 > 知识库问答 >
问题:

注意:php中用于显示数据库中图像的未定义索引

孙书
2023-03-14

我正在用php开发一种社交网络类型的项目,但在某个地方遇到了麻烦,无法显示数据库中的use图像

注意:C:\wamp\www\collegenetworking\profileleft中未定义的索引:usimg。php第19行

profile.php

<?php
include("header.php");
include("profilesql.php");
include("friends.php"); 
?>
<center>
<div class=container>
<div class=container>

<!-- head --><!-- navigation menu -->
<?php include("head.php"); ?>
<?php
include("menu.php"); 
$result = mysql_query("SELECT * FROM profile ORDER BY RAND()");
$i=0;
while($row = mysql_fetch_array($result))
  {
      if($row["userid"] != $_SESSION["stuid"] )
{ 
$img[$i] = $row["image"];
$uid[$i] = $row["userid"];
$city[$i] = $row['city'];
$i++;
  }
  }
  $result = mysql_query("SELECT * FROM stuacc where id");  

$strec = mysql_query("SELECT * FROM stuacc WHERE email='$_SESSION[logid]' ");

while($row = mysql_fetch_array($strec))
  {
$_SESSION["stuid"] =  $row["id"];

  }

$colrec = mysql_query("SELECT * FROM profile WHERE userid='$_SESSION[stuid]' ");

while($row = mysql_fetch_array($colrec))
  {
$cname = $row["coluni"];
  }

$acrec1 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[0]' ");

while($row = mysql_fetch_array($acrec1))
  {
      $stid1 = $row["id"];
$name1 = $row["firstname"];
$gen1= $row["iam"];
  }

  $acrec2 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[1]' ");

while($row = mysql_fetch_array($acrec2))
  {
          $stid2 = $row["id"];
$name2 = $row["firstname"];
$gen2= $row["iam"];
  }

  $acrec3 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[2]' ");

while($row = mysql_fetch_array($acrec3))
  {
          $stid3 = $row["id"];
$name3 = $row["firstname"];
$gen3= $row["iam"];
  }

  $acrec4 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[3]' ");

while($row = mysql_fetch_array($acrec4))
  {
          $stid4 = $row["id"];
$name4 = $row["firstname"];
$gen4= $row["iam"];
  }
?>


<div style="padding: 10px; text-align: left;">
<!-- body  content -->

    <table width="100%" height="382" border="0" >
  <tr>
    <td width="16%" rowspan="9" align="left" valign="top" bgcolor="#CCCCCC"><?php include("profileleft.php"); ?></td>
    <td width="55%" rowspan="9" valign="top"><table width="100%" border="1">
        <tr>
          <th scope="col"><strong>Welcome, <?php echo $_SESSION["logid"]; ?></strong></th>
          </tr>
        <tr>
          <td><strong>Number of visitors:
              <?php
if(isset($_SESSION['views']))
 $_SESSION['views']=$_SESSION['views']+1;
   else
 $_SESSION['views']=1;
 echo $_SESSION['views']; 
 ?>
          </strong></td>
          </tr>
        <tr>
         <?php if(isset($cname)) { ?> <td><strong>College Name : </strong><b><?php echo $cname ; ?></b></td><?php } ?>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <table width=100%>

        <tr valign=top align=center>
          <td colspan="4" align="left"><strong>Request Friends</strong></td>
          </tr>
        <tr valign=top align=center>
            <td><a href="friendsprofile.php?fid=<?php echo $stid1 ; ?>"><img src="<?php echo $img[0] ; ?>" width="100" height="150" border="0" alt=""><br />
             <?php echo $name1 ; ?><br />

            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid2 ; ?>""><img src="<?php echo $img[1] ; ?>" width="100" height="150" border="0" alt=""><br />
              <?php echo $name2 ; ?>
            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid3 ; ?>""><img src="<?php echo $img[2] ; ?>" width="100" height="150" border="0" alt=""><br />
             <?php echo $name3 ; ?>
            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid4 ; ?>""><img src="<?php echo $img[3] ; ?>" width="100" height="150" border="0" alt=""><br />
              <?php echo $name4 ; ?>
            </a><br></td>

        </tr>
        </table>
      <table width="100%" border="1">
      <tr>
        <th colspan="2" scope="col"><br />            &nbsp;     <?php echo $fname. " " . $lname; ?></th>
      </tr>
      <tr>
        <?php if(isset($cname)) { ?><td colspan="2"><strong>College Name : </strong><b><?php echo $cname ; ?></b></td> <?php } ?>
      </tr>
      <tr>
        <?php if(isset($fmes)) { ?><td width="51%"><strong>City :<?php echo $_GET["fmes"]; ?></strong></td><?php } ?>

        </tr>
      <tr>
        <td height="23"><strong>State:</strong></td>
        <?php if(isset($state)) { ?><td><?php echo $state; ?></td><?php } ?>
        </tr>
      <tr>
        <td height="23"><strong>Pincode:</strong></td>
        <?php if(isset($pincode)) { ?><td><?php echo $pincode; ?></td><?php } ?>
        </tr>
      <tr>
        <td height="23"><strong>Country:</strong></td>
        <?php if(isset($country)) { ?><td><?php echo $country; ?></td><?php } ?>
        </tr>
      </table></td>
      <td height="23" colspan="2" background="" bgcolor="#CCCCCC"><strong><u>My friends</u></strong></td>
  </tr>
  <tr>
    <td width="14%" height="23" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[0] ; ?>" alt="" width="71" height="53" /></td>
    <td width="15%" height="23" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[1] ; ?>" alt="" width="71" height="53" /></td>
  </tr>
  <tr>
    <td height="4" align="center" valign="top" bgcolor="#CCCCCC"><img src="<?php echo $img[2] ; ?>" alt="" width="71" height="53" /><br />      
      <br /></td>
    <td height="4" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[3] ; ?>" alt="" width="71" height="53" /></td>
  </tr>
  <tr>
    <td height="21" colspan="2" align="center" valign="top" bgcolor="#CCCCCC"><strong><a href="viewall.php">View all</a></strong></td>
  </tr>
  <tr>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/alosious.jpg" alt="" width="77" height="75" /></td>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/alvas.jpg" alt="" width="96" height="96" /></td>
  </tr>
  <tr>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/canara.jpg" alt="" width="78" height="78" /></td>
    <td height="36" bgcolor="#CCCCCC"><img src="images/dhavala.jpg" alt="" width="96" height="74" /></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC" align="center"><strong>View all</strong></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC"><strong><u>Advertisement</u></strong></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC" align="center"  ><a href="http://www.admissionopen.com/" ><img src="images/advt.jpg" width="173" height="185" /></a></td>
  </tr>
  </table>


</div>
<center>
<?php include("footer.php"); ?>

共有1个答案

关正雅
2023-03-14

换行

<a href="profile.php"><img src="<?php echo $usimg;?>" alt="" 
width="90" height="106" /></a><br>

对这个

<a href="profile.php">
 <?php if(isset($usimg)) { ?>
  <img src="<?php echo $usimg;?>" alt="" width="90" height="106" />
  <?php } ?>
</a><br>

添加isset功能。如果userimg存在,则显示图像。您可以添加else部分,并在用户没有图像的情况下显示一些通用图像。

文档链接:http://www.php.net/isset

 类似资料:
  • 问题内容: 我正在运行一个 PHP 脚本并继续收到如下错误: 注意:未定义变量:第 10 行 C:\wamp\www\mypath\index.php 中的 my_variable_name 注意:未定义索引:第 11 行的 my_index C:\wamp\www\mypath\index.php 第 10 行和第 11 行如下所示: 这些错误消息的含义是什么? 为什么它们会突然出现?我曾经使用

  • 问题内容: 我正在运行PHP脚本,并继续收到如下错误: 注意:第10行上C:\ wamp \ www \ mypath \ index.php中的未定义变量:my_variable_name 注意:未定义的索引:第11行的my_index C:\ wamp \ www \ mypath \ index.php 第10和11行看起来像这样: 这些错误消息是什么意思? 为什么它们突然出现?我曾经使用此

  • 本文向大家介绍PHP 注意:未定义的索引 PHP Notice: Undefined index,包括了PHP 注意:未定义的索引 PHP Notice: Undefined index的使用技巧和注意事项,需要的朋友参考一下 示例 原因: 尝试通过数组中不存在的键访问数组 可能的解决方案: 访问前请检查可用性。采用: isset() array_key_exists()

  • 被一个问题缠住了。我是android开发的新手。我的问题是我有一个SQLite数据库,我正在其中保存映像和一些数据,但当我检索这些数据时,映像没有显示在ListView中。其他数据正在被推翻。 这是我的自定义列表布局 null 这是我的自定义适配器 } 这是activity 这是数据列表

  • 我想在我的应用程序中显示来自sqlite数据库的图像。我的要求是显示文本视图及其相关图像。我将我的数据库文件保存在资产文件夹中。但实际上我的图像存储在服务器的“allimages”文件夹中。 我的数据库列(我保留的assets文件夹中的db)如下所示: S.无描述 1 div style=“文本对齐:对齐;” 2 div style="文本对齐:对齐;" 现在我的问题是在我的数据库中,图像路径存储

  • 在FOP 2.6中,我尝试将FO文件转换成PDF。我在Windows上使用标准配置文件。 由于不支持一种图像格式,我创建了一个自定义的PreLoader、ImageLoaderFactory和ImageConverter。它们是通过服务条目注册的,从日志中我可以看到它们正在被使用: 但图像不会显示在生成的PDF文件中。。。 转换器将自定义格式转换为PNG并返回RAW_PNG: 我也曾试图皈依JPG

  • 我的程序在Eclipse中运行完美,但是当我导出它时,图像不显示出来。 我的设置看起来像 我参考标志。来自MenuMain的png。java,我尝试了很多方法; 前3个在Eclipse中工作,但都不在Jar中工作。我检查了Jar文件,res文件夹在那里,所有的图像也是如此。我还尝试编辑MANIFEST. MF并添加了类路径: 但它仍然不起作用。我在运行Jar时没有发现任何错误,其他所有内容都显示在

  • 我仍然是PHP的新手(昨天刚开始),当我想删除我的数据时,它说: 注意:未定义的索引:第13行C:\wamp64\www\HelpingClass\delete.php中的书名 注意:未定义的索引:C中的数量:###############################################################################################