php Undefined index配置文件错误

时间:2014-02-22 05:59:11

标签: php html

我正在制作社交网络类型的项目,我也在做一些项目。在这里我得到第15行的未定义索引错误,我无法解决..&

profileleft.php

<SCRIPT language="JavaScript1.2">
function openwindow()
{
    window.open("chat/mychat.php","mywindow","menubar=1,resizable=1,width=350,height=750");
}
</script>
<br /><center>
<a href="profile.php">
 <?php if(isset($usimg)) { ?>
  <img src="<?php echo $usimg;?>" alt="" width="90" height="106" />
  <?php } ?>
</a><br>
      <font color="#000099"><strong><?php echo $fname ." ".$lname; ?></strong><br />
  <a href="changepic.php">Change Picture</a>
</center>
     <hr /> 
     <img src="images/icon/profile.gif" width="23" height="22" align="absmiddle" />  <a href="editprof.php" >Edit Profile</a><br />
<a href="msg.php"><img src="images/icon/messages.gif" width="27" height="24" align="absmiddle" /> Scrap</a><br />
      <a href="answer.php"><img src="images/icon/answers.png" width="25" height="24" align="absmiddle" /> Answers    </a><br />
<a href="viewuploads.php"><img src="images/uploads.png" alt="" width="27" height="26" align="absmiddle" /></a><a href="viewuploads.php">View Uploads</a><br />

        <a href="javascript: openwindow()" ><img src="images/chat.png" width="25" height="24" align="absmiddle" /> Chat </a>
<p>&nbsp;</p>

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(isset($row["userid"]) && $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"><?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"); ?>

profile

friendsprofile.php

<?php
session_start();
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"); 
if($_GET["addf"]=="t")
    {
        $sql="INSERT INTO addfriends(meid,friendid) VALUES
    ('$_SESSION[stuid]','$_GET[fid]')";
        if (!mysql_query($sql,$con))
            {
                die('Error: ' . mysql_error());
            }
    }
$result = mysql_query("SELECT * FROM stuacc where id=$_GET[fid]");
while($row = mysql_fetch_array($result))
    {
        $fname = $row["firstname"];
        $lname = $row["lastname"];
    }

$result1 = mysql_query("SELECT * FROM profile where userid=$_GET[fid]"); 

while($row = mysql_fetch_array($result1))
    {
        $usimg = $row["image"];
        $city = $row["city"];
        $state = $row["state"];
        $pincode = $row["pincode"];
        $country= $row["country"];
        $hschoool= $row["hschool"];
        $coluni= $row["coluni"];
        $course= $row["course"];
    } 

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

while($row = mysql_fetch_array($colrec))
    {
        $cname = $row["coluni"];
    }
$result = mysql_query("SELECT * FROM profile ORDER BY RAND()");
$i=0;
while($row = mysql_fetch_array($result))
    {

        $img[$i] = $row["image"];
        $uid[$i] = $row["userid"];
        $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="19%" rowspan="10" align="left" valign="top" bgcolor="#CCCCCC">

    <br /><center>
    <a href="profile.php"><img src="<?php echo $usimg;?>" alt="" width="90" height="106" /></a><br>
    <font color="#000099"><strong>
    </strong></center>
    <hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=Added as friend&addf=t">
    <img src="images/icon/profile.gif" width="23" height="22" align="absmiddle" />  Add As Friend</a><br />
    <p>&nbsp;</p>


</td>
<td width="50%" rowspan="10" valign="top"><table width="100%" border="1">
    <tr>
    <th colspan="2" scope="col"><br />            &nbsp;     <?php echo $fname. " " . $lname; ?></th>
</tr>
<tr>
<td colspan="2"><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 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 } ?>
<td width="49%"><?php echo $city; ?></td>
</tr>
<tr>
<td height="23"><strong>State:</strong></td>
    <td><?php echo $state; ?></td>
</tr>
<tr>
<td height="23"><strong>Pincode:</strong></td>
    <td><?php echo $pincode; ?></td>
</tr>
<tr>
<td height="23"><strong>Country:</strong></td>
    <td><?php echo $country; ?></td>
</tr>
<tr>
<td height="23"><strong>High Shcool:</strong></td>
    <td><?php echo $hschoool; ?></td>
</tr>
<tr>
<td height="23"><p><strong>College/Univesity:</strong></p></td>
    <td><?php echo $coluni; ?></td>
</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>View all</strong></td>
    </tr>
    <tr>
    <td height="21" colspan="2" align="left" valign="top" bgcolor="#CCCCCC"><strong><u>Colleges</strong></td>
    </tr>
    <tr>
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td>
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td>
    </tr>
    <tr>
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td>
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></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">&nbsp;</td>
</tr>
</table>


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

3 个答案:

答案 0 :(得分:2)

生成错误是因为您的$ _GET [“addf”]未设置为仍在检查其值的任何内容。所以它的未定义索引错误。

如果你把

放在当前行
if(isset($_GET["addf"]) && $_GET["addf"]=="t")

在第15行,它将检查它的设置是否等于 t 然后将遵循其if条件。好运和这个&amp;记得在遇到未定义的错误时检查变量是否在其使用之前被索引。

答案 1 :(得分:1)

Here i am getting undefined index error on line 15 which i cant solve..

代码的第15行包含:

if($_GET["addf"]=="t")

你高兴地检查它的,而不检查它的存在

你可以做(​​并且有习惯):

if(isset($_GET["addf"]) && $_GET["addf"]=="t")

您也可以通过以下方式关闭通知,但将来您会获得性能提升,这不是一个好习惯,也是懒惰。

if(@$_GET["addf"]=="t")

你也写这个:

<hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=Added as friend&addf=t">

请注意,fmes包含空格,必须使用urlencode()

对其进行正确编码
<hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=<?php echo urlencode("Added as friend"); ?>&addf=t">

答案 2 :(得分:-1)

试试这个

    $sql="INSERT INTO addfriends(meid,friendid) VALUES
('".$_SESSION['stuid']."','".$_GET[fid]."')";

因为你的会话var必须是“或” 您可以使用if(isset($_GET["addf"]))检查var或使用'@',例如@$_GET["addf"]